unknown php-mysql UPDATE error :/

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

unknown php-mysql UPDATE error :/

Post by Coco »

weird little problem here :/
im trying to do an update, the query is:

Code: Select all

UPDATE users SET reg_date = reg_date, rate_num = rate_num + 1, rate_sum = rate_sum + 5 WHERE id = '920c13683f0c4ca048b68640f3ec1078'
Now ive phpmyadmin open at the same time, and ive tried that exact same query in phpm.a. and it worked

but when i run it in php i get
UPDATE users SET reg_date = reg_date, rate_num = rate_num + 1, rate_sum = rate_sum + 5 WHERE id = '920c13683f0c4ca048b68640f3ec1078'
Warning: Supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/uo-auction2.com/httpdocs/bfeedback.php on line 169
Abnormal database error.
The php is:

Code: Select all

<?php
$query5 = 'UPDATE ' . $tableusers . ' SET reg_date = reg_date, rate_num = rate_num + 1, rate_sum = rate_sum + ' . $HTTP_POST_VARS[rate] . " WHERE id = '" . $target . "'";
$result5 = mysql_query($query5);
echo $query5;
if(mysql_num_rows($result5)<1)//line 169
{
	echo 'Abnormal database error.<br>' . mysql_error();
	exit;
}
?>
Can someone please put me out of my misery and tell me why a query that works in phpmyadmin doesnt work in php itself :(
CONFIQ
Forum Commoner
Posts: 32
Joined: Fri Oct 18, 2002 3:39 pm
Location: Israel - Raanana

Post by CONFIQ »

Try this to see mysql_error
$result5 = mysql_query($query5) or die(mysql_error());
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

i already have mysql_error inside the if loop... and it returned no error
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

that error usually means that there is a field which doesnt exist, or you've misspelt it.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

if you read again, you will see that i cut and pasted EXACTLY the same query into phpmyadmin and it worked
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Perhaps mysql_error() is returning nothing because it's being called after mysql_num_rows() and:
PHP manual wrote:this function only returns the error text from the most recently executed MySQL function
It would be a good idea to add an or die() statement with mysql_error() (as CONFIQ suggested) to see if there is an error being returned by mysql_query().

You have connected to MySQL and selected the required database and that's not thrown any errors?

Mac
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

It still doesnt give an error
i changed it to

Code: Select all

<?php
//--
$result5 = mysql_query($query5);
echo $query5 . ' ' . mysql_error();
//--
?>
And theres still no error output
theres about 6 queries before this one so its not a connection error
Post Reply