2014-02-24 71 views
0

我有一個PHP頁面,接受來自前一頁張貼的價值,這貼值分配給一個變量,但在同一個頁面後分配崗位價值變量或會話VAR我有一個按鈕,重新加載導致發佈值爲「null」的頁面。即時獲取未確定的索引通知。而且我也試着用isset函數解決它也不行。嘗試將它分配給一個會話變量,也即時得到相同的錯誤!關於如何解決這個問題的任何想法?重新加載相同頁面

<?php 
session_start(); 
include_once("config.php"); 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Shopping Cart</title> 
<link href="style/style.css" rel="stylesheet" type="text/css"> 
</head> 

<body> 
<div id="products-wrapper"> 
    <h1>products</h1> 
    <div class="products"> 
    <?php 
    //current URL of the Page. cart_update.php redirects back to this URL 

    $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); 
    if (isset ($_POST["shop_id"])) { $_SESSION["shop_id"] = $_POST['shop_id'];} 
    $results = $mysqli->query("SELECT * FROM products2 where shop_id='".$_SESSION["shop_id"]."'"); 
    if ($results) { 

     //fetch results set as object and output HTML 
     while($obj = $results->fetch_object()) 
     { 
      echo '<div class="product">'; 
      echo '<form method="post" action="cart_update.php">'; 
      echo '<div class="product-thumb"><img src="images/'.$obj->product_img_name.'"></div>'; 
      echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>'; 
      echo '<div class="product-desc">'.$obj->product_desc.'</div>'; 
      echo '<div class="product-info">'; 
      echo 'Price '.$currency.$obj->price.' | '; 
      echo 'Qty <input type="text" name="product_qty" value="1" size="3" />'; 
      echo '<button class="add_to_cart">Add To Cart</button>'; 
      echo '</div></div>'; 
      echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />'; 
      echo '<input type="hidden" name="type" value="add" />'; 
      echo '<input type="hidden" name="return_url" value="'.$current_url.'" />'; 
      echo '</form>'; 
      echo '</div>'; 
     } 

    } 
    ?> 
    </div> 
+0

您是否在上面使用'session_start()'開始了會話? –

+0

是的會議已經開始在前面的頁面 – user3280207

回答

0

試試這個,在頁面頂部添加@session_start();

if (isset ($_POST["shop_id"])) { $_SESSION["shop_id"] = $_POST['shop_id'];} 
+0

試過了,仍然得到相同的通知!注意:未定義的變量:_SESSION in ... – user3280207

+0

在頁面頂部添加「@session_start();'。 –

+0

ughh注意:會話已經開始 - 忽略前一頁中的session_start() – user3280207

相關問題