【问题标题】:Hidden form relate to targetID隐藏形式与 targetID 相关
【发布时间】:2013-10-20 18:18:09
【问题描述】:

我目前正在尝试解决编辑产品,当我按下编辑产品时,它的效果很好,可以显示所有内容,并允许我查看提交的产品图像和文本以供我们更新。

在我按下提交后,会更新到数据库中,但之后我在同一页面中遇到与它所说的表单内部相关的错误

<label>
    <input name="thisID" type="hidden" value="<?php echo $targetID  ?>" />
    <input type="submit" name="button" id="button" value="Make change" />
</label>

这个错误说

Notice: Undefined variable: targetID in C:\VertrigoServ\www\shopone\admin\data\edit_product.php on line 147 Call Stack #TimeMemoryFunctionLocation 10.0010352200{main}( )..\edit_product.php:0 " />

请查看完整表格部分并在行尾查看...

<form id="form1" name="form1" method="post" action="edit_product.php">
  <table width="80%" cellpadding="2" cellspacing="2">

      <tr>
           <?php echo '<td width="36%" rowspan="9" align="right">  <img src="' . GW_UPLOADPATH . '/' . $screenshot .'" width="351" height="402" />  </td>'; ?>
        <td class="text-box1">Product Name:</td>
        <td>&nbsp;</td>
        <td><input name="product_name" type="text" class="text-field1" id="product_name" value="<?php echo $product_name; ?>" /></td>
        <td colspan="2"><!-- Icons --></td>
      </tr>
      <tr>
        <td class="text-box1">Product Category:</td>
        <td>&nbsp;</td>
        <td><input name="product_category" type="text" class="text-field1" id="product_category" value="<?php echo $product_category; ?>" /></td>
        <td colspan="2"><!-- Icons --></td>
      </tr>
      <tr>
        <td class="text-box1">Product Retail Price:</td>
        <td>&nbsp;</td>
        <td><input name="product_retail_price" type="text" class="text-field1" id="product_retail_price" value="<?php echo $product_retail_price; ?>" /></td>
        <td colspan="2"><!-- Icons --></td>
      </tr>
      <tr>
        <td class="text-box1">:Product price:</td>
        <td>&nbsp;</td>
        <td><input name="product_price" type="text" class="text-field1" id="product_price" value="<?php echo $product_price; ?>" /></td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td class="text-box1">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td class="text-box1">Images</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2"><!-- Icons --></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label>
          <input name="thisID" type="hidden" value="<?php echo $targetID  ?>" />
          <input type="submit" name="button" id="button" value="Make change" />
        </label></td>
      </tr>
    </tbody>
  </table>
</form>

在 php 部分...

<?php 
$dbcs = new mysqli("localhost", "root", "password", "shopone");


// Check connection
if (mysqli_connect_errno($dbcs))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
// Parse the form data and update company information to the system
if (isset($_POST['product_name'])) {

    $pid = $_POST['thisID'];
    $product_name = $_POST['product_name'];
    $product_category = $_POST['product_category'];
    $product_retail_price = $_POST['product_retail_price'];
    $product_price = $_POST['product_price'];

$sql = "UPDATE product SET
    product_name='$product_name', 
    product_category='$product_category', 
    product_retail_price='$product_retail_price',
    product_price='$product_price'
    WHERE product_id='$pid'";

$result = mysqli_query($dbcs,$sql);

if(!$sql)
{
print "error";

}
else 
{
header("product.php");
}}


// Gather these companies full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
    $targetID = $_GET['pid'];
    $sql = "SELECT * FROM product WHERE product_id='$targetID' LIMIT 1";
  $result=mysqli_query($dbcs,$sql);

      while($row = mysqli_fetch_array($result)){ 
               $product_id = $row["product_id"];
             $product_name = $row["product_name"];
             $product_category = $row["product_category"];
             $product_retail_price = $row["product_retail_price"];
             $product_price = $row["product_price"];
             $screenshot =$row["screenshot"];

        }
}

mysqli_close($dbcs);
?>

有谁知道是什么意思以及如何解决这个问题!

【问题讨论】:

    标签: php forms select mysqli edit


    【解决方案1】:

    当您按下提交按钮时,您将变量从 $_GET 更改为 $_POST 是 php 中的另一个脚本,我认为您必须实现。 但如果你想试试……试试这个:

    if (isset($_GET['pid'])) {
        $targetID = $_GET['pid'];
        $sql = "SELECT * FROM product WHERE product_id='$targetID' LIMIT 1";
      $result=mysqli_query($dbcs,$sql);
    
          while($row = mysqli_fetch_array($result)){ 
                   $product_id = $row["product_id"];
                 $product_name = $row["product_name"];
                 $product_category = $row["product_category"];
                 $product_retail_price = $row["product_retail_price"];
                 $product_price = $row["product_price"];
                 $screenshot =$row["screenshot"];
    
            }
    }
    else{
       if (isset($_POST['pid'])) {
          $targetID = $_POST['pid'];
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-25
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多