Jump to content

php warning mesage


subhomoy

Recommended Posts

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
Share on other sites

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
Share on other sites

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.