Jump to content

Help with if statement


denoteone

Recommended Posts

I want to write and IF statement that will check to see if a users IP and the date match a date and IP in my database. this way if the ip has been added already this day I can just add the page they went to instead of creating a whole new entry

 

$visitor_ip = $_SERVER['REMOTE_ADDR'];
$visitor_day = date("d");
$visitor_page = curPageURL();  //function that gets the page they are visiting.

mysql_select_db($database_visitors, $visitors);
                   if(check to see if $visitor_ip is in the data base and if it is see if the field visitor day is equal to $visitor_day if it is... ){

on that match only append $visitor_page to the visitor_page colum 


} else{
$sql = "INSERT INTO visitor_list (visitor_ip, visitor_whois, visitor_min, visitor_hour, visitor_day, visitor_month, visitor_year, 
visitor_ref, visitor_page) VALUES ('$visitor_ip','$ip_info','$visitor_hour', '$visitor_minute', '$visitor_day', '$visitor_month','$visitor_year', '$visitor_ref', '$visitor_page')";

$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
}

Link to comment
Share on other sites

$sql = mysql_query(sprintf("SELECT `visitor_ip`,`visitor_day` FROM `visitors_list` WHERE `visitor_ip` = '%u' AND `visitor_day` = '%u';",(int)$visitor_ip,(int)$visitor_day)) or die('error!');
if(mysql_num_rows($sql)) {

    // A record exists.

} else {

    // no record exists insert.

}

Link to comment
Share on other sites

So the code that gos in between the if statement would look some thing like this???

 

$sql = mysql_query(sprintf("SELECT `visitor_ip`,`visitor_day` FROM `visitors_list` WHERE `visitor_ip` = '%u' AND `visitor_day` = '%u';",(int)$visitor_ip,(int)$visitor_day)) or die('error!');

if(mysql_num_rows($sql)) {

    $sql = update 'visitor_list' where visitor_ip and visitor_date are = to $visitor_ip and $visitor_date, append visitor_page with $visitor_page;

$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);

 

} else {

 

    // no record exists insert.

 

}

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.