2016-06-25 94 views
-1

我有在PHP的錯誤信息像這樣的「無在線未定義的索引ID:」我一直在使用下面的代碼PHP錯誤 - 未定義指數:ID

$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++; 
      } 
      ?> 

上市下面的代碼,我有使用

<?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)){ ?> 

我沒有足夠的PHP經驗,所以你可以請檢查這段代碼,並告訴我如何解決這個問題。

+0

你測試isset。是嗎? –

+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Qirel

回答

0

刪除單引號像$id=$_REQUEST['id']; 這裏$queryImg = "SELECT * FROM data WHERE country='".$_REQUEST['id']."'";

0

剛從變量$id刪除該帖,這樣的:在$ ID,但查詢在$ _REQUEST [ID]

$id=$_REQUEST['id'];