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:[EMAIL PROTECTED]]
>Sent: Monday, February 26, 2001 10:36 AM
>To: Peter Houchin; PHP MAIL GROUP
>Subject: Re: [PHP] Script not updating
>
>
>From: "Peter Houchin" <[EMAIL PROTECTED]>
>
>
> > 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: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
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]