PHP/mySQL trouble...
Has any one ever had the problem that with an Update query.. it doesn't update?
I have ran the same query through mySQL and it works fine but when I come to run it through my script it doesn't update. All of the variables that go through the query are set. I have a field that resets itself to 0 when you update???!
What's goin on?
mairving posted this at 10:16 — 1st August 2002.
They have: 2,256 posts
Joined: Feb 2001
The best way to tell what is going on is to echo your query to the screen to see if it is passing values to the database.
anti posted this at 11:22 — 1st August 2002.
They have: 453 posts
Joined: Jan 1999
and if that doesn't help, an
echo mysql_error( );
is your friend.
a_gajic posted this at 21:04 — 1st August 2002.
They have: 71 posts
Joined: Aug 2001
Okay guys this is what happens...
When I echo the variables they are fine and they show up...
There is no mysql_error(); text either, any more ideas?
the script is for an edit page on my forums that I am creating the query is like this
$query = "UPDATE topics SET tsubject='$tsubject' AND tbody='$tbody' WHERE (tid=$tid)";
$result = mysql_query($query);
if (!$result) {
echo "Error in query<br>\n";
echo mysql_error();
}
any ideas?
ROB posted this at 00:05 — 2nd August 2002.
They have: 447 posts
Joined: Oct 1999
are you sure $tid has a value and the record exists in the database?
zollet posted this at 02:18 — 2nd August 2002.
He has: 1,016 posts
Joined: May 2002
a_gajic,
Try the following..
<?php
$query = \"UPDATE topics SET tsubject='$tsubject' AND tbody='$tbody' WHERE (tid=$tid)\";
$result = mysql_query($query);
if (mysql_errno()) {
echo \"Error in query<br>\n\";
echo mysql_errno() . \" - \" . mysql_error();
}
?>
The reason why I suggest this is because when you run an UPDATE query, it does not return a TRUE or FALSE value in $result.
Mark Hensler posted this at 06:49 — 2nd August 2002.
He has: 4,048 posts
Joined: Aug 2000
SET doesn't use the AND field seperator, it uses the coma.
$query = "UPDATE topics SET tsubject='$tsubject', tbody='$tbody' WHERE tid='$tid'";
zollet posted this at 07:10 — 2nd August 2002.
He has: 1,016 posts
Joined: May 2002
Mark, nice catch! I didn't even bother looking at the query when I saw the !$result part.
Cheers.
a_gajic posted this at 23:19 — 2nd August 2002.
They have: 71 posts
Joined: Aug 2001
damnit.. thanks Mark - I knew that I hate it when that happens lol.. thanks for the info about the query not retrieving a true/false value too
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.