Peter,
In case "AAA" When $submit is set, you will always get an an insert; you
have a mysql_query executing.
In case "BBB" you are only assigning the SQL statement to $result, I didn't
look further to see where it executes. It really doesn't matter because
case "AAA" will always fire first.
Can you structure your flow so that, depending on your conditions you
assign the SQL statement to a variable, such as $sql_string, and then at
the end of your conditions execute $result = mysql_query( $sql_string ); ?
This also looks like a scenario where having a good hard look at using
switch ... case .. break. I've really liked it for control structures
involving buttons.
You may also want to consider redisplaying your input page with a flag
identifying the missing or incorrect values. Julie Meloni has a very nice
example of this at http://www.thickbook.com
Hope you are having lovely weather. Our forecast tonight is snow, followed
by ice pellets, freezing rain, rain and then back to snow. All that's
missing is the sunshine!
Regards - Miles Thompson
At 10:30 AM 2/26/01 +1100, Peter Houchin wrote:
>Could some one please have a look thru my code and tell me why it creates
>a new record instead of updating the record?
>
>What this script is suposed to do is show a HTML form .. then once the
>user fills it out it then shows another form which echo's the values
>inputted in the first so the user can update if they made a mistake .. it
>does everything right .. up until the user clicks on update ... where
>instead of updating the record it creates a new one ..
>
>Any sussestions/Help would be greatful
>
>
>Peter Houchin
>Sun Rentals
>[EMAIL PROTECTED]
>
><?
>$db = mysql_connect("localhost","root","password");
> mysql_select_db("rentdb",$db);
>
>if ($submit){
"AAA"
>
> $result = mysql_query("INSERT INTO app
> (name,company,address,suburb,state,post,areacode,phone,faxareacode,fax,email,secret)
> VALUES
>
>('$name','$company','$address','$suburb','$state','$post','$areacode','$phone','$faxareacode','$fax','$email','$secret')");
>
> if($name){
> $result="SELECT * FROM app WHERE name=$name";
> if ($submit){
>
> $result ="UPDATE app SET
>
>name='$name',company='$company',address='$address',suburb='$suburb',state='$state',post='$post',areacode='$areacode',phone='$phone',faxareacode='$faxareacode',fax='$fax',email='$email',secret='$secret'
>
> WHERE name=$name";
>echo mysql_error();
>
>}
<snip>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]