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.. Quote Link to comment Share on other sites More sharing options...
Solution runnerjp Posted April 9, 2013 Solution 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.