2013-05-11 71 views
0

我無法找到解決此問題的解決方案。我遇到很大的問題,我不知道解決了我會等待解決方案,並感謝你。問題在域名中嗎?獲取警告「mysql_fetch_assoc():提供的參數不是有效的MySQL結果資源」

<?php 

session_start(); 

require_once("../Connections/Store.php"); 

if(isset($_GET['page'])){ 

    $pages = array("products","cart"); 


if(in_array($_GET['page'],$pages)){ 


     $page=$_GET['page']; 

     }else { 

      $page="products"; 


    } 

}else { 



    $page="products"; 

} 


?> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<link rel="stylesheet" href="css/reset.css" /> 
<link rel="stylesheet" href="css/style.css" /> 


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 

</head> 

<body> 
<div id="container"> 
<div id="main"><?php require($page. ".php"); ?></div> 

<div id="sidebar"></div> 

<?php 

if(isset($_SESSION['cart'])){ 


    $sql .="SELECT * FROM products WHERE pro_id IN ("; 


foreach($_SESSION['cart'] as $id => $value){ 

     $sql .=$id . ","; 


     } 


     $sql = substr($sql,0,-1). ") ORDER BY pro_id ASC"; 


$query=mysql_query($sql); 
     while($row=mysql_fetch_assoc($query)){ 




     ?> 

     <p><?php echo $row['pro_name'];?><?php echo $_SESSION['cart'][$row['pro_id']] 

['quantity'];?></p> 
     <a href="index.php?page=cart">Go to Cart </a> 

     <?php 

      } 



}else { 

      echo"Your Cart is empty. <br> please add some product"; 

      } 



     ?> 




</div> 
</body> 
</html> 
+0

'mysql_'函數已被棄用。見http://www.php.net/manual/en/function.mysql-fetch-assoc.php – Mooseman 2013-05-11 11:52:09

回答

2

您的查詢失敗使用mysql_error從這裏

$sql .="SELECT * FROM products WHERE pro_id IN ("; 
    ^^ 

注意查看錯誤

$query=mysql_query($sql) or die(mysql_error()); 

,並刪除.Please, don't use mysql_* functions in new code。他們不再維護and are officially deprecated。請參閱red box?請改爲了解prepared statements,並使用PDOMySQLi - this article將幫助您決定哪個。如果您選擇PDO,here is a good tutorial

+1

謝謝你,你的偉大:) – 2013-05-11 12:13:01

相關問題