0

セッション変数 $_SESSION['id'] をあるページから別のページに渡そうとしています。しかし、それを渡そうとするページで、このエラーが発生します Undefined index id

ページは異なるディレクトリにありますが、明らかに同じ親ディレクトリにあります。これは何か関係がありますか?

これが最初のファイルです

session_start();
include 'connect.php';
if(isset($_POST['category'])){
  // cast the category to integer (just a little bit of basic security)
  $cat = (int) $_POST['category'];
  $q = "SELECT * FROM products WHERE cat=$cat AND status = 1 ORDER BY id DESC";
  $result = $link->query($q);
  // this will be the string that you will return into the product-data div
  $returnHtml = '';
 }
 else if(isset($_POST['subcategory'])){
  // cast the category to integer (just a little bit of basic security)
  $subcat = (int) $_POST['subcategory'];
  $q = "SELECT * FROM products WHERE subcat=$subcat AND status =1 ORDER BY id DESC";
  $result = $link->query($q);
  // this will be the string that you will return into the product-data div
  $returnHtml = '';
 }
     // construct the html to return
     while($row = mysqli_fetch_array($result)) {
    $returnHtml .= "<div class='product'>"; 
    $returnHtml .= "<a href='products.php' target='_blank''>";
    $returnHtml .= "<img class='nailthumb-container'";
    $returnHtml .= "src='{$row['image']}' ";;
    $returnHtml .= "alt='{$row['name']}' ";
    $returnHtml .= "title='{$row['name']}' />";
    $returnHtml .= "</a>";
    $returnHtml .= "<span class='productname1'>{$row['name']}</span>";
    $returnHtml .= "<br />";
    $returnHtml .= "<br />";
    $returnHtml .= "<span class='productprice1'>&pound {$row['price']}</span>";
    $returnHtml .= "</div>";
    $_SESSION['id']=$row['id'];
}

// display the html (you actually return it this way)
echo $returnHtml;

これは2番目です

 <?php session_start(); ?>
 <html xmlns="http://www.w3.org/1999/xhtml">
        <div class="productconainer">
           <?php
              $id = "SELECT * FROM products WHERE id = '".$_SESSION['id']."'";
              $result = $link->query($id);
              while($row = mysqli_fetch_array($result)) {
    echo $row['image'];
     }
           ?>
</body>
</html>
4

1 に答える 1

0

Undefined index: id は次の行にあると思います:

$_SESSION['id']=$row['id'];

if!isSet($_POST['category'])および!isSet($_POST['subcategory']) 変数$rowが定義されていません。

于 2013-08-25T11:36:08.817 に答える