Jump to content


Photo

Mysql value not updating?


  • Please log in to reply
4 replies to this topic

#1 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 16 July 2006 - 05:20 AM

           $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";
When i go back to the page that this is on the value is always 1.
what can i do to fix this?



Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 July 2006 - 05:22 AM

what's in num in your database?  is there one entry for each page view?

#3 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 16 July 2006 - 05:23 AM

num is the number of views

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 July 2006 - 05:26 AM

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

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

When testing, don't use the @ error suppression.
Legend has it that reading the manual never killed anyone.
My site

#5 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 16 July 2006 - 05:28 AM

I tried that, but it still doesn't work  :(

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users