Jump to content

Mysql value not updating?


fert

Recommended Posts

[code]
           $cn=@mysql_connect("","","") or die(mysql_error());
@mysql_select_db("",$cn) or die(mysql_error());
$result=@mysql_query("SELECT num FROM views",$cn) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$num=$row[num];
}
$num++;
$result=@mysql_query("UPDATE views SET num='$num' WHERE num!='$num'",$cn) or die(mysql_error());
echo "There have been $num views of this page";
[/code]
When i go back to the page that this is on the value is always 1.
what can i do to fix this?

Link to comment
https://forums.phpfreaks.com/topic/14740-mysql-value-not-updating/
Share on other sites

[code]$result=@mysql_query("UPDATE views SET num='$num' WHERE num!='$num''",$cn) or die(mysql_error());[/code]

There's an error in that compounded statement. ... num!='$num' ' = unmatched quotes.  The query is failing.

When testing, don't use the @ error suppression.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.