Re: SQL update does insert? [solved]
| From: | Erik | Date: | Wed, 12 Jul 2000 15:21:51 +0000 |
| Subject: | Re: SQL update does insert? [solved] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6154@lists.php.net to get a copy of this message | ||
Operator error (again):
preceeding this SQL update I had an INSERT stmt
which was being executed each time, based on an
assignment that was masquerading as a test:
if( $this='string') {
has a very different effect than:
if ( 'string' == $this )
A nod to any rookies reading this: note the order of
the string and the variable in the second example.
If one of the '=' signs is missing it will not
acidentally assign values to the variable because
of the left-to-right relationship. THIS IS A GOOD PRACTICE RULE: TEST WITH
THE VARIABLE
ON THE RIGHT SIDE and save yourself and
others some grief.
humbly, Erik
----- Original Message -----
From: "Craig Vincent" <2bunnyhop@home.com>
To: <stainsby@telus.net>; <php-general@lists.php.net>
Sent: Wednesday, July 12, 2000 5:26 AM
Subject: RE: [PHP] SQL update does insert?
> <snip>
> $q = "update jump set ordinal=$ordinal,label='$label',url='$url' where
> idx=$idx)";
> $r = mysql_query( $q );
>
> $r seems to come out of this undefined <?>
> print $r; gives back nothing.
>
> Echoing the query string looks quite as I expect it should; appropriate
> quotes
> and string values everywhere. I'm quite baffled.
>
> The idx column is not null auto_increment primary key, ordinal is int(4),
> the
> other two are varchar.
>
> Guesses and/or clues?
> </snip>
>
> That's incredibly bizarre...especially since the UPDATE feature of MySQL
> should NEVER do any new record inserts...that's what REPLACE is for :) If
> it is trying to actually add a new record there may be a bug either in
that
> particular version of PHP or perhaps in the MySQL client compiled into
PHP.
> My best suggestion to you is to at least upgrade to PHP 3.0.16 or better
yet
> to 4.0.0pl2 using that lastest MySQL client include files.
>
> Have you checked the MySQL logs? Perhaps they can reveal more information
> on exactly what PHP is trying to do.
>
> Sincerely,
>
> Craig Vincent
>