我有一个与我创建的产品数据库相关的网站,该数据库存储在phpmyadmin中。我在用户和管理员之间分开了访问权限。我试图让管理员在成功登录后通过网站更新产品数量和价格。到目前为止,我已经能够在页面上的表格中显示所有产品及其当前数量而没有任何问题。然后,我已经捕获了产品ID,并希望在点击更新链接后将此产品ID转移到下一页。我尝试使用以下代码执行此操作:
//SQL query to retrieve stock quantity for the all Products
//store the result in an array then in a new variable
$stockSQL="select prodName, prodPrice, proQuantity from Products order by prodId";
$exestockSQL=mysql_query($stockSQL) or die(mysql_error());
while ($stocklevel=mysql_fetch_array($exestockSQL))
{
echo "<tr>";
//display products name
echo "<td>".$stocklevel['prodName']."</td>";
//display products price
echo "<td>".$stocklevel['prodPrice']."</td>";
//display product quantity
echo "<td>".$stocklevel['proQuantity']."</td>";
echo "<td><a href=editproddetails.php?u_prodid=".$stocklevel['prodId'].">Update</td>";
echo "</tr>";
下一页(在href中标题为editproddetails.php)应该使用此id来显示项目点击的具体细节。通过用户访问路径,我有一组几乎相同的代码,用户点击主页上的项目,产品ID存储并传送到下一页,这样可以正常工作。所以我很确定这不是这一部分,但我不确定。我试图在表格中显示当前的信息。以下是我对单个项目更新页面的代码:
<?php
session_start();
//include a db.php file to connect to database
include("db.php");
//create a variable called $pagename which contains the actual name of the page
$pagename="Update Selected Product Information";
//call in the style sheet called ystylesheet.css to format the page as defined in the style sheet
echo "<link rel=stylesheet type=text/css href=mystylesheet.css>";
//display window title
echo "<title>".$pagename."</title>";
//include head layout
include("adminheadlayout.html");
//display the name of the site and the date dynamically. See uk.php.net
echo date ('l d F Y H:i:s');
echo "<p></p>";
include ("detectlogin.php");
//display name of the page
echo "<h2>".$pagename."</h2>";
//retrieve the Products id passed from the previous page using the $_GET superglobal variable
//store the value in a variable called $prodid
$prodid=$_GET['u_prodid'];
//echo "<p>Selected product Id: ".$prodid;
//query the Products table to retrieve the record for which the value of the product id
//matches the Products id of the product that was selected by the user
$prodSQL="select prodId, prodName, prodPicName, prodDescrip , prodPrice, proQuantity from Products where prodId=".$prodid;
//execute SQL query
$exeprodSQL=mysql_query($prodSQL) or die(mysql_error());
//create array of records & populate it with result of the execution of the SQL query
$thearrayprod=mysql_fetch_array($exeprodSQL);
echo "<p><table border=1 cellpadding=5>";
//display product name in capital letters
echo "<tr><td colspan=2><center><b>".strtoupper($thearrayprod['prodName'])."</b></center></td></tr>";
//display product picture
echo "<tr><td colspan=2><center><img src=Images/".$thearrayprod['prodPicName']."></center></td></tr>";
//display product description
echo "<tr><td colspan=2>".$thearrayprod['prodDescrip']."</td></tr>";
echo "<form action=editstock.php method=post>";
//display product price
echo "<tr><td>PRICE: ".$thearrayprod['prodPrice']."</td>";
echo "<td><input type=text name=p_priceupdate size=5 maxlength=3></td></tr>";
//display stock level
echo "<tr><td>AVAILABLE IN STOCK: ".$thearrayprod['proQuantity']."</td>";
echo "<td><input type=text name=p_quantityupdate size=5 maxlength=3></td></tr>";
echo "<tr><td colspan=2><input type=submit value='UPDATE'></td></tr>";
echo "<input type=hidden name=h_prodid value=".$stockid.">";
echo "</center>";
echo "</form>";
echo "</table>";
//display form made of one text box and one button for user to enter quantity
//pass the product id to the next page basket.php as a hidden value
echo "<form action=basket.php method=post>";
echo "<p><center>Quantity: ";
echo "<input type=text name=p_quantity size=5 maxlength=3>";
echo "<input type=submit value='Add to Basket'>";
echo "<input type=hidden name=h_prodid value=".$prodid.">";
echo "</center>";
echo "</form>";
//include head layout
include("footlayout.html");
?>
此页面返回结果“您的SQL语法中有错误;请查看与您的MySQL服务器版本对应的手册,以便在第3行附近使用正确的语法”。最令我困惑的是,我已经为我的产品详细信息页面运行了相同的代码,我刚刚更改了数组名称。我在第二页中定义了u_prodid的值,该值应该是从上一页发送的,如上面的代码所示。
我已经尝试了许多代码变体,我担心它只是我不知道的东西,我愚蠢地忘记了安排查询等规则之一。我已经检查了代码,解剖了但仍然无济于事。