subhomoy Posted April 9, 2013 Share Posted April 9, 2013 here is a little bit of code that i've done to check the values against the database values. Every Thing is working fine but i'm getting an warning message. I can't get rid of the warning message. plz help me. The code is shown below <?php echo $ip = $_SERVER['REMOTE_ADDR']; echo "<br />"; echo $date = date("Y-m-d"); echo "<br />"; $ip1 = mysql_query("SELECT * FROM ip WHERE date='$date' AND ip='$ip'"); while($row = mysql_fetch_array($ip1)){ $d = $row['date']; $i = $row['ip']; } if($i == $ip && $d == $date) <--------------------------------------------------------------------- the warnings.... echo 'You have already visited the page today.'; else { $insert_ip = mysql_query("INSERT INTO ip (id,date,ip) VALUES('','$date','$ip')") or die(mysql_errno()); echo 'Thank you for your visit'; } ?> The warnig mesage i'm getting is Notice: Undefined variable: i in C:\xampp\htdocs\Mobitalk\index.php on line 23 Any help will be appreciated.. Link to comment https://forums.phpfreaks.com/topic/276724-php-warning-mesage/ Share on other sites More sharing options...
runnerjp Posted April 9, 2013 Share Posted April 9, 2013 An Undefined index means that you are referencing an array index that doesn't exist yet. Have you checked if $i is set? <?php echo $ip = $_SERVER['REMOTE_ADDR']; echo "<br />"; echo $date = date("Y-m-d"); echo "<br />"; $d = ""; $i = ""; $ip1 = mysql_query("SELECT * FROM ip WHERE date='$date' AND ip='$ip'"); while($row = mysql_fetch_array($ip1)){ $d = $row['date']; $i = $row['ip']; } if($i == $ip && $d == $date) <--------------------------------------------------------------------- the warnings.... echo 'You have already visited the page today.'; else { $insert_ip = mysql_query("INSERT INTO ip (id,date,ip) VALUES('','$date','$ip')") or die(mysql_errno()); echo 'Thank you for your visit'; } ?> TRY THE ABOVE Link to comment https://forums.phpfreaks.com/topic/276724-php-warning-mesage/#findComment-1423713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.