php自动填充表单不填充MySQL表数据,但具有表ID号

时间:2017-09-17 02:46:32

标签: php mysql autofill

我正在尝试使用PHP从MySQL数据库中自动填充表格,但它会自动填充所有带有数字1的表单空间。该数字是我选择在其上编辑的特定产品的ID号。以前的网页。我缩短了表格,所以没有太多的代码可供查看。

<?php

   //Check that a product ID is specified for the page
    if (isset($_GET['ItemID'])) {
        $productID = $_GET['ItemID'];
   }else{
        header("Location: ../update.php");
   }

    if (isset($_POST['Name'])) {
       $Name = $_POST['Name'];
       $Description = $_POST['Description'];

      $updateQuery = "
UPDATE item 
   SET name = '$Name'
     , Description = '$Description' 
 WHERE condition = '$Description' 
 WHERE ID= $productID";

     $mysqli->query($updateQuery);
     echo ("Product successfully updated"); 
   }


    $query = "
SELECT * 
  FROM item 
 WHERE ItemID = $productID
";
    $result = $mysqli->query($query);

  if($result->num_rows > 0) {
        $data = $result->fetch_array(MYSQLI_BOTH);


?>

 <h2> Edit Product </h2>
 <form action="edit.php?ItemID=<?php echo ($productID); ?>" method="POST" >
        <fieldset>
            <h4>Sell Your Item</h4>
            <p><label class="title" for="Name">Name:</label>
            <input type="text" placeholder="<?php echo ($productID); ?>" name="Name" id="Name" title="Please enter item name" 
            ><br />

            <label class="title" for="Description">Description:</label>
            <textarea name="Description" rows="5" cols="33" placeholder="<?php echo ($productID); ?>"  id="Description" title="Please describe your item" >
  </textarea><br />
  </fieldset>
  </form>

 <?php 
   }
  ?>

0 个答案:

没有答案