Jump to content

php warning mesage


subhomoy
 Share

Go to solution Solved by runnerjp,

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

  • Solution

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

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.