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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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