Jump to content

Archived

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

fert

Mysql value not updating?

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?

Share this post


Link to post
Share on other sites
what's in num in your database?  is there one entry for each page view?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
I tried that, but it still doesn't work  :(

Share this post


Link to post
Share on other sites

×

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.