Jump to content

[SOLVED] Reading Database Problem


SoireeExtreme

Recommended Posts

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";
    }

Link to comment
https://forums.phpfreaks.com/topic/74948-solved-reading-database-problem/
Share on other sites

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");

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";
    }

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..

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.