RE: [PHP] Script not updating
| From: | (Miles Thompson) | Date: | Mon, 26 Feb 2001 00:18:36 +0000 |
| Subject: | RE: [PHP] Script not updating | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41621@lists.php.net to get a copy of this message | ||
The query flagged by if ($submit) will always fire first, and it appears you will always have a $name value as well. I believe it's actually firing twice in some scenarios - runs the insert and then immediately updates.
Will $submit contain different values? Then
switch ( $submit )
{
case "update":
$sql = "update blah blah ....";
break;
case "new":
$sql = "insert into blah blah ...";
break;
default:
echo "No value to process for submit";
unset( $sql );
}
if isset( $submit )
{
$result = mysql_query( $sql );
.... and so forth ..
}
With this structure you can use an array to hold the value of your buttons, such as $action[ ], in which case the switch statement is "switch( $action[0] )"
Cheers - Miles
Miles
At 10:43 AM 2/26/01 +1100, Peter Houchin wrote:
but that's why i've got the if($name){ .... if($submit) ... clause in it .. thinking that if there was a name then update the record.. otherwise create a new one -----Original Message----- From: Simon Garner [mailto:sgarner@expio.co.nz] Sent: Monday, February 26, 2001 10:36 AM To: Peter Houchin; PHP MAIL GROUP Subject: Re: [PHP] Script not updating From: "Peter Houchin" <peterh@vfsa.com.au> Could some one please have a look thru my code and tell me why it creates a new record instead of updating the record? [snip] if ($submit){ $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','$phon e','$faxareacode','$fax','$email','$secret')"); ^^ Here's your culprit. Check your logic. Whenever they push submit it INSERTs a new record (I think...). Regards Simon Garner -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net