Php 如何从数据库中检索数据?

Php 如何从数据库中检索数据?,php,mysql,database,Php,Mysql,Database,我无法检索产品的名称、描述、价格和图片,这是代码,除了:Pice:和“添加到购物车”按钮之外,我什么也没有得到。当我在名称、图片、描述和价格之后运行var_dump($row)时,它在浏览器上返回NULL <? require "C:/xampp/htdocs/shopping/shopping/includes/db.php"; require "C:/xampp/htdocs/shopping/shopping/includes/functions.php"; if($_REQUES

我无法检索产品的名称、描述、价格和图片,这是代码,除了:Pice:和“添加到购物车”按钮之外,我什么也没有得到。当我在名称、图片、描述和价格之后运行var_dump($row)时,它在浏览器上返回NULL

<?
require "C:/xampp/htdocs/shopping/shopping/includes/db.php";
require "C:/xampp/htdocs/shopping/shopping/includes/functions.php";

if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
    $pid=$_REQUEST['productid'];
    addtocart($pid,1);
    header("location:shoppingcart.php");
    exit();
}
     ?>
    <!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>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Products</title>
     <script language="javascript">
function addtocart(pid){
    document.form1.productid.value=pid;
    document.form1.command.value='add';
    document.form1.submit();
}
  </script>
  </head>


 <body>
 <form name="form1">
<input type="hidden" name="productid" />
    <input type="hidden" name="command" />
  </form>
    <div align="center">
<h1 align="center">Products</h1>
<table border="0" cellpadding="2px" width="600px">
    <?
        $result=mysql_query("SELECT * FROM products");
        while($row=mysql_fetch_array($result)){
    ?>
    <tr>
        <td><img src="<?=$row['picture']?>" /></td>
        <td>    <b><?=$row['name']?></b><br />
                <?=$row['description']?><br />
                Price:<big style="color:green">
                    $<?=$row['price']?></big><br /><br />
                <input type="button" value="Add to Cart" onclick="addtocart(<? =$row['serial']?>)" />
        </td>
    </tr>
    <tr><td colspan="2"><hr size="1" /></td>
    <? } ?>
  </table>
  </div>
  </body>
  </html>

产品
函数addtocart(pid){
document.form1.productid.value=pid;
document.form1.command.value='add';
文件。表格1。提交();
}
产品
" />


价格: $


您实际连接到数据库了吗?db.php中有什么?请打印$result=mysql\u查询的输出(“从产品中选择*”);@Sabari您是指表产品的内容吗?@Isabella,您确认您的查询没有给出任何错误,并且没有返回空的结果集吗?能否将
echo mysql_error();
echo mysql_num_rows($result);
放在调用mysql_query()的行之后?重复:
<?
mysql_connect("localhost","root","") or die("DB error");
mysql_select_db("shopping") or die("DB error");
session_start();

?>