Php 更新循环不工作

Php 更新循环不工作,php,Php,我正在尝试通过$\u post数据进行循环更新,但更新不起作用 require_once("include/session.php"); require_once("include/dataconnect.php"); require_once("include/functions.php"); if(array_key_exists('item', $_POST)){ $items = $_POST['item']; //Loop through $_POST items,

我正在尝试通过$\u post数据进行循环更新,但更新不起作用

require_once("include/session.php");
require_once("include/dataconnect.php"); 
require_once("include/functions.php"); 
if(array_key_exists('item', $_POST)){
    $items = $_POST['item'];
    //Loop through $_POST items, updating the database for each item
    foreach ($items as $item) { 
        $Pquantity = intval($item[0]);
        $Pidno = intval($item[1]);
        $queryreg = mysql_query("
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       username = '{$_SESSION['username']}'
        "); 
    }
这是发送数据的表单

 echo "
<form action='updatepplac.php' method='Post' class='slistbar'>
<table border='1'>
  <tr>
    <th>SHOP NAME</th>
    <th>PRODUCT NAME</th>
    <th>PRODUCT SIZE</th>
    <th>PRODUCT COLOUR</th>
    <th>PRODUCT QUANTITY</th>
    <th>PRICE</th>
    <th></th>
  </tr>";
echo”
店名
产品名称
产品尺寸
产品颜色
产品数量
价格
";
//获取数据库结果并循环,使用计数器输出表行

$pplresult = mysql_query("SELECT * FROM repplac") or die(mysql_error());
for ($i = 0; $row = mysql_fetch_assoc($pplresult); $i++) 
{
    echo "
      <tr>
        <td>".htmlspecialchars($row['Sname'])."</td>
        <td>".htmlspecialchars($row['Pname'])."</td>
        <td>".htmlspecialchars($row['Psize'])."</td>
        <td>".htmlspecialchars($row['Pcolour'])."</td>
        <td>
          <input type='text' name='item[$i][Pquantity]' id='Pquantity' 
    value='".htmlspecialchars($row['Pquantity'])."' />
          <input type='hidden' name='item[$i][Pidno]' id='Pidno' value='".htmlspecialchars($row['Pidno'])."' />
        </td>
        <td>".htmlspecialchars($row['Price'])."</td>
        <td><a href='deleteproduct.php?del=".htmlspecialchars($row['Pidno'])."'>delete</a></td>
      </tr>";
  }
$pplresult=mysql\u查询(“从repplac中选择*”)或die(mysql\u error());
对于($i=0;$row=mysql\u fetch\u assoc($pplresult);$i++)
{
回声“
.htmlspecialchars($row['Sname'])
.htmlspecialchars($row['Pname'])
.htmlspecialchars($row['Psize'])
.htmlspecialchars($row['Pcolour'])
.htmlspecialchars($row['Price'])
";
}

首先将$\u会话['username']存储在变量中,然后在查询中使用它。因此,您的查询应该类似于

$username=$\会话['username']


$queryreg=mysql_查询(“更新repplac SET Pquantity='$Pquantity',其中Pidno='$Pidno'和username='$username')

将sql查询回显给您自己并查看它。如果正确,则执行mysql_查询(…您的查询…)或死亡(mysql_错误());“不工作”是什么意思?我的水晶球今天在商店里。除了回显查询,当你向你的
mysql\u查询添加
或死亡(mysql\u error())
时,它告诉你什么?当我回显查询时,它返回的是旧数据,而不是更新的数据data@lostty84
它返回旧数据
此数据来自表单。可能是您从表单发送的不是您需要的数据。我在循环中分配了值,但没有给出结果。我这样做对吗?您可以粘贴用于获取项目post数据“”的html代码吗;打印(邮政美元);回声“;或者是你要的表格吗?我已经编辑了问题,并将表格粘贴在问题的底部(但没有很好地发布)