Page 1 of 1

[SOLVED] MySQL Update Query Prob

Posted: Wed Apr 07, 2004 7:35 pm
by RealmX
I've been having a terrible time with this update code for MySQL. I've searched all over the internet, looked up examples, and it still doesn't help me. The problem I'm having is that my variable $count does not get updated in the database query.

Code: Select all

$id=$_GET['id'];
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM links";
$result=mysql_query($query);

$count=mysql_result($result,($id),"count");
$count++;

$query = "UPDATE links SET count='$count' WHERE id = $id";
mysql_query($query);
echo mysql_error();
mysql_close();
Any help would be greatly appreciated as I'm quite new to PHP and MySQL.
?>[/php_man]

Posted: Wed Apr 07, 2004 7:39 pm
by markl999
Try..

Code: Select all

$db = mysql_connect('localhost',$user,$password) or die(mysql_error());
mysql_select_db($database) or die('Unable to select database');

$query = "UPDATE links SET count=count+1 WHERE id = {$_GET['id']}";
mysql_query($query) or die(mysql_error());
mysql_close($db);

Posted: Wed Apr 07, 2004 8:02 pm
by RealmX
That worked very well, thanks :D