更新数据,但希望数据在sql视图中并进行更改


Update data, but want the data in sql view and change it

Hye,我能问一些问题吗。我想使用在数据库中设置的id更新数据库中的数据。数据可以更新,但我希望在更新页面中。数据库中的信息首先被查看,我可以为新的输入删除和更改。编码就在这里。你能告诉我怎么做吗?

           <?php
           require "cn.php";
           $query=mysql_query("select*from medicine");
       $num=1; 
           ?>   

          <!DOCTYPE HTML> 
          <head>
          <style>
          body
          {
          background:url("pharmacy.jpg");
          background-size:2000px 1100px;
          background-repeat:no repeat;
          padding-top:40px;
          }
          </style> 
          <title>View Stock</title>
          </head>
          <table align="center" width="800" border="5" bgcolor="white"  bordercolor="red">
          <tr>
          <td><div align="center"><a href="mainpage.php" >HOME</div></a></td>
          <td><div align="center"><a href="stock.php">STOCK</div></a></td>
          <td><div align="center"><a href="view.php">REPORT</div></a></td>
          <td><div align="center"><a href="staff.php">UPDATE INFORMATION</div></a></td>
          </tr>
          </table>
          <br>
          <br>
          <br>
          <br>

          <div align="middle">
          <table  border="5"  bgcolor="white" bordercolor="red">
          <tr align="middle">
          <td>No</td>
          <td>Code</td>
          <td>Medicine</td>
          <td>Stock</td>
          <td>Price</td>
          <td colspan="2">action</td>
           </tr>
          <?php
          while($fetch=mysql_fetch_object($query)) 
          {
          ?>
          <tr>
          <td><?php echo $num;?></td>
          <td>  <?php echo $fetch->code;?></td>
      <td><?php echo $fetch->medicine;?></td>
      <td><?php echo $fetch->stock;?></td>
      <td><?php echo $fetch->price;?></td>
      <td><a href="update.php?id=<?php echo $fetch->id;?>">update</a></td>
      <td><a href="deleteh.php?id=<?php echo $fetch->id;?>">delete</a></td>
      </tr>

          <?php
          $num++;
          }
          ?>
          </div>
          </table>
          </html>

Update.php编码

          <?php

          if(isset($_GET['id']))
          $id=$_GET['id'];
          ?>
         <!DOCTYPE  HTML>
         <head>
         <title>Update stock</title>
         <style>
         body
         {
         background:url("pharmacy.jpg");
         background-size:2000px 1100px;
         background-repeat:no repeat;
         padding-top:40px;
         }
         </style>
         </head>
         <form Action="updateh.php" method="post"> 
         <table align="center" width="800" border="5" bgcolor="white" bordercolor="red">
         <div align="center"><h2>Enter New Update</h2></div>
         <tr>
         <td align="center" colspan=4>Name</td>
         </tr>
         <br>
         <div align="right">
         <a href="view.php"><font color="white">Back to Stock Update</a></font><br>

         </div>
         <tr> 
         <td><div align="center">Code</div></td>
         <td><div align="center">Medicine</div></td>
         <td><div align="center">Stock</div></td>
         <td><div align="center">Price(RM)</div></td>
         </tr>
         <tr> 
         <td><div align="middle"><input type="textbox" name="code" required></div></td>
         <td><div align="middle"><input type="textbox" name="medicine" required></div></td>
          <td><div align="middle"><input type="textbox" name="stock" required></div></td>
          <td><div align="middle"><input type="textbox" name="price" required></div></td>
          </tr>
          <tr>
          <td align="middle" colspan=4><input type="submit" value="update">
          <input type="hidden" name="id" value="<?php echo $id;?>"> 
          </td>
          </tr>
          </table>
          </Form>
          </html>

updateh.php编码

    <?php
    session_start();
    require "cn.php";
    $id=$_POST['id'];
    $code=$_POST['code'];
    $medicine=$_POST['medicine'];
    $stock=$_POST['stock'];
    $price=$_POST['price'];
    mysql_query("update medicine set code='$code', medicine='$medicine', stock='$stock', 
    price='$price' where id='$id'");
    echo header("location: sucess2.php");

     ?>
if(isset($_POST['submit'])) {
   $code= $_POST['code'];
   $medicine= $_POST['medicine'];
   $stock= $_POST['stock'];
   $price= $_POST['price'];
   $sql= mysql_query(UPDATE `your_table` SET `code`,`medicine`,`stock`,`price`) VALUES ('$code','$medicine','stock','$price') WHERE `id`='$id';
}

使用此项,然后读取并使用mysqli而不是mysql