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
https://forums.phpfreaks.com/topic/151078-help-with-if-statement/
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.

}

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.

 

}

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.