页面需要刷新才能加载内容

时间:2015-08-30 05:30:00

标签: php

我有一个购物网站。因为当我们点击某个特定产品时,它将获取该产品的ID,并将使用该ID加载另一个页面。但是当我打开网站并点击任何页面未显示的产品时。它继续加载。当我重新加载它工作正常。它只在第一次发生。之后,当我点击产品时,页面会显示。请帮我。提前谢谢

我已附上网页代码

     $id = $_GET['id'];
   $_SESSION['abaya']= $id;

以上代码是我获取ID的地方。我附上了下面的特定页面

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Abayat Dubai</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 


</head>

<body>
<section id="portfolio" class="portfolio">
<div class="container">

<div class="row">


        <div class="span6" style="float:left">



            <?php
$code="{$_SESSION['abaya']}";  
?>  


               <!--begin span4 -->

                   <div class="view view-first" id="frockone">

                           <img src="images/photos/<?php echo"$code";?>.jpg" alt="frock">


                   </div>


        </div>


        <div class="span5" style="float: right; padding-left:5%">


        <?php
        $query="SELECT * FROM s_product WHERE code='$code';";
$result=mysql_query($query)
or die("could not perform query");
$name="{$_SESSION['country']}";
$price="error";

while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$p_name="{$row['img_name']}";
?> 

        <h4><?php echo"{$row['img_name']}";?></h4>


        <p>Description : <?php echo"{$row['description']}";?> </p>






        <?php if($name=="sri"){

                                $currency="LKR ";
$price="{$row['sri_price']}";

               }
elseif($name=="uae"){

                                $currency="AED ";
$price="{$row['price']}";

}

elseif($name=="australia"){
$currency="AUD ";
$price="{$row['australia_price']}";
}
else{
$currency="USD ";
$price="{$row['usa_price']}";
}?>

          <h6 style="color:#a62b6d; font-size:18px"> <span><?php echo"$currency","$price"?></span></h6>


       <?php 
$price_us="{$row['usa_price']}";

break;
}?>
       <hr>
        <div>



<form name="product" method="post" action="pro.php">

       <select name="quantity" style="width:100px; padding:2%">
  <option selected="selected" value="">Quantity</option>
<option value="1">1</option>
<option value="2">2</option>
  <option value="3">3</option>
                    <option value="4">4</option>
  <option value="5">5</option>

</select><br />



            <select name="size" style="width:100px; padding:2%">
  <option selected="selected" value="">Size</option>

<option value="50">50</option>
  <option value="52">52</option>
  <option value="54">54</option>
                    <option value="56">56</option>
  <option value="58">58</option>
</select>
<br /><br />
         <input type="submit" class="btn btn-small btn-primary btn-embossed but" value="Add To Bag"  onclick="return validate()" name="add_cart" style="margin-right:5%"/>


 <a href="sale_home.php"> Continue shopping!</a>



         <br />


 </form>


<?php  
if(isset($_SESSION['user_tempid']))
{?>
<?php }else{
date_default_timezone_set('Asia/Dubai');
$today = date("Y-m-d H:i:s");  
$_SESSION['user_tempid']="$today";
$i=1;
$query8="select * from temp_id;";
    $result8=mysql_query($query8) or die("can not login");
    while($row=mysql_fetch_array($result8,MYSQL_ASSOC)){

if($row['id']=="$today"){
$_SESSION['user_tempid']="$today$i";
$i++;
}
}
}
 ?>




  <?php
if(isset($_POST["add_cart"]))
{  
$quantity=$_POST["quantity"];
$size=$_POST["size"];
$cost=$quantity*$price;
$usd=$quantity*$price_us;
$query="INSERT INTO  temp_cartitem(user_id,product_id,size,quantity,ori_price,cost,product_name,currency,usd)  VALUES('{$_SESSION['user_tempid']}','$code','$size','$quantity','$price','$cost','$p_name','$currency','$usd')";
 $result= mysql_query($query) or die("failed to insert your record"); 





 //header('location:cart.php');
   }
 ?>




        </div>

         <hr>







        </div>

</div>

<br /><br /><br />


            <!--end small list-->
 </div>
</section>


</div>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

您是否在为会话变量赋值之前发出了session_start()?