denoteone Posted March 25, 2009 Share Posted March 25, 2009 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 More sharing options...
POG1 Posted March 25, 2009 Share Posted March 25, 2009 $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 https://forums.phpfreaks.com/topic/151078-help-with-if-statement/#findComment-793667 Share on other sites More sharing options...
denoteone Posted March 25, 2009 Author Share Posted March 25, 2009 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 https://forums.phpfreaks.com/topic/151078-help-with-if-statement/#findComment-793756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.