SoireeExtreme Posted October 27, 2007 Share Posted October 27, 2007 Hi, I'm having a problem reading the database. But I assume its due to the fact that I have done some very bad coding lol... I'm still fairly new. So forgive me. A little info... I'm trying to set up a so called counter. When someone opens a page it will check to see if someone has been to the site before and if they have it will add a 1 to visits. And if the person hasn't been to the site before it will insert their ip along with 1 visit to the database. As you can see this is being done by reading the persons ip address. But instead of updating an ip address with visits... It keeps inserting and inserting. Never updating... Could someone look at this code and perhaps help me? Any help would be greatly appreciated. Thank you in advance... If you need more info please let me know. $s=$_SERVER["REMOTE_ADDR"]; $ID=$_GET['ID']; $checkip="SELECT id from a_recordips where ip='$s'"; $checkip2=mysql_query($checkip) or die(mysql_error()); $checkip3=mysql_num_rows($checkip2); if($checkip3['ip']=='$s') { $updateip="update a_recordips set visits=visits+,'1' where ID='$checkip3[iD]'"; mysql_query($updateip) or die("Could Not Update IP Records"); echo"IP updated"; } else { $updaterecords="INSERT into a_recordips (ID,ip,visits) values ('$ID','$s','1')"; mysql_query($updaterecords) or die("Could Not Insert IP Records"); echo"IP Record Added"; } Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/ Share on other sites More sharing options...
lemmin Posted October 27, 2007 Share Posted October 27, 2007 "$checkip3" isn't an array. Change: if($checkip3['ip']=='$s') to: if($checkip3) Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-378983 Share on other sites More sharing options...
SoireeExtreme Posted October 27, 2007 Author Share Posted October 27, 2007 Thanks, but when I do that it still can't update. It read Could Not Update IP Records as I wanted it to when it fails. What seems to be wrong now? $updateip="update a_recordips set visits=visits+,'1' where ID='$checkip3[iD]'"; mysql_query($updateip) or die("Could Not Update IP Records"); Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-378984 Share on other sites More sharing options...
teng84 Posted October 27, 2007 Share Posted October 27, 2007 visits+,'1' <-- remove the comma Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-378986 Share on other sites More sharing options...
SoireeExtreme Posted October 27, 2007 Author Share Posted October 27, 2007 haha stupid comma... That also helped... But it still does not update the database where it says visits... It still remains at 1 from where it was inserted to begin with... It does not want to update visits... AS we walk step by step lol... Whats the problem now please... Thanks for the help so far... $s=$_SERVER["REMOTE_ADDR"]; $ID=$_GET['ID']; $checkip="SELECT id from a_recordips where ip='$s'"; $checkip2=mysql_query($checkip) or die(mysql_error()); $checkip3=mysql_num_rows($checkip2); if($checkip3) { $updateip="update a_recordips set visits=visits+'1' where ID='$checkip3[iD]'"; mysql_query($updateip) or die("Could Not Update IP Records"); echo"IP updated"; } else { $updaterecords="INSERT into a_recordips (ID,ip,visits) values ('$ID','$s','1')"; mysql_query($updaterecords) or die("Could Not Insert IP Records"); echo"IP Record Added"; } Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-378989 Share on other sites More sharing options...
darkfreaks Posted October 27, 2007 Share Posted October 27, 2007 <?php $updateip='update a_recordips set visits=visits+'1' where ID='.$checkip3[iD].'';?> Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-378991 Share on other sites More sharing options...
SoireeExtreme Posted October 27, 2007 Author Share Posted October 27, 2007 Thanks darkfreaks, but that doesn't help solving or fixing my problem in anyway. All I get is an error message... Parse error: syntax error, unexpected T_LNUMBER in D:\xampp\htdocs\article\index.php on line 12 Any other help would be greatly appreciated... Thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-379011 Share on other sites More sharing options...
SoireeExtreme Posted October 27, 2007 Author Share Posted October 27, 2007 Thanks for the help everyone... This topic is solved... ID='$checkip3[iD]' need to be changed to $checkip3... And thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/#findComment-379017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.