Log in

View Full Version : Table update problem



Rockonmetal
04-17-2008, 09:27 PM
I am having a problem with this table updating
The code should take the max id from the user and turn it into a variable though its not letting me do it...


$con = mysql_connect("localhost","admin","");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("markmon_pureadd_upload", $con);
$result= mysql_query("SELECT MAX(ID) FROM pictures WHERE user='$user'");//Selects max ID from the specific user specified
while($row = mysql_fetch_array($result)){
mysql_query("UPDATE pictures SET status='102' WHERE ID='$result' AND user='$user'");

Now when I put in a value for id like id=1 it will update the status... but when i have it trying and do it with the variable... it won't...
Thanks!

city_coder
04-17-2008, 09:58 PM
i know its the tedious testing stuff but have you tried echoing out the $result variable. just to see what exactly is in it. iv had problems in the past where iv just had to declare the variable to make sure it is set properly.

passing the obvious test, try seeing if you can convert it. there is no reason why it shouldn't be going in fine but you never know, it can happen.

http://www.phpf1.com/tutorial/php-string-to-int.html

try that, tedious and obvious and you prob deserve more credit, but hey its worth a go if you havent already checked

Rockonmetal
04-17-2008, 11:01 PM
I get Resource id #3 when I echo it and thats not the max value or the next max value. This is starting to make less and less sense...

Nile
04-18-2008, 01:43 AM
Everything that is not an MySQL command should be ticked, try this:

$con = mysql_connect("localhost","admin","");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("markmon_pureadd_upload", $con);
$result= mysql_query("SELECT MAX(ID) FROM `pictures` WHERE `user`='{$user}'");//Selects max ID from the specific user specified
while($row = mysql_fetch_array($result)){
mysql_query("UPDATE `pictures` SET `status`='102' WHERE ID='$result' AND `user`='{$user}'");