-1

I have got an error message in php like this "undefined index id in line no:", I have using the following code

$id='$_REQUEST[id]';
            $sql = "SELECT * FROM country";
            $result = $con->query($sql);
            $i=1;
            foreach($result as $row)
            {
                ?>
             <li><a href="data.php?id=<?php echo $row['id'] ?>"><?php echo $row['name'] ?> </a></li>   
                 <?php
                $i++;
            }
            ?>

For listing the following code i have used

<?php
if(isset($id))     {   
   $queryImg = "SELECT * FROM data WHERE country='$_REQUEST[id]'"; 
   $resultImg = mysqli_query($con,$queryImg);
   $rowResult = mysqli_num_rows($resultImg);
   while($rowsImg = mysqli_fetch_array($resultImg)){ ?>

I do not have enough experience in php, so can you please check this code and tell me how to solve this.

Sudeep
  • 35
  • 8
  • You test isset on $id but query on $_REQUEST[id]. is that it? – Moussa Khalil Jun 25 '16 at 07:56
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Qirel Jun 25 '16 at 08:25

2 Answers2

0

remove single quotes like $id=$_REQUEST['id']; and here $queryImg = "SELECT * FROM data WHERE country='".$_REQUEST['id']."'";

dod29
  • 105
  • 7
0

Just remove the quote from the variable $id, like this:

$id=$_REQUEST['id'];
Pang
  • 9,564
  • 146
  • 81
  • 122
P.Coder
  • 94
  • 9