更新mysql数据库中的数据

时间:2013-03-24 08:05:29

标签: php mysql updates

//我有3个.php。代码没有给出任何错误,但它没有;修改数据。第一个是edit.php,这里是以下代码:

    <?php

       include"db.php";//database connection


        /*$result = mysql_query("SELECT * FROM inward ");
    $row = mysql_fetch_array($result);*/
          $order = "SELECT * FROM inward";
          $result = mysql_query($order);
          while ($row=mysql_fetch_array($result))
          {
           $inwardid = $row['inwardID'];    
                    echo "<tr align='center'>"; 
                    echo"<td><font color='black'>" .$row['inwardID']."</font></td>";
                    echo"<td><font color='black'>" .$row['inreceiptno']."</font></td>";
                    echo"<td><font color='black'>". $row['inreceiptdt']. "</font></td>";
                    echo"<td><font color='black'>". $row['sendername']. "</font></td>";
                    echo"<td><font color='black'>". $row['senderaddress']. "</font></td>";  
                    echo"<td><font color='black'>" .$row['insubject']."</font></td>";
                    echo"<td><font color='black'>" .$row['inacceptedby']."</font></td>";
                    echo"<td><font color='black'>" .$row['inreceiptmode']."</font></td>";
                    echo"<td><font color='black'>" .$row['remark']."</font></td>";
                    echo"<td><font color='black'>" .$row['person']."</font></td>";
                    echo"<td><font color='black'>" .$row['duedate']."</font></td>";
                    echo"<td><font color='black'>" .$row['compliancemode']."</font></td>";
                    echo"<td><font color='black'>" .$row['adreceiptdate']."</font></td>";
                    echo"<td><font color='black'>" .$row['filename']."</font></td>";

            echo ("<td><a href=\"edit_form.php?id=".$row['inwardID']."\">Edit</a></td></tr>");

          }
    ?>

//我的第二个文件名是edit_form.php。源代码是:

  <?php
      include "db.php";//database connection
      $id = $_GET["id"];

     /* $result = mysql_query("SELECT * FROM inward WHERE inwardID='$id'");
$row = mysql_fetch_array($result);*/


       $order = "SELECT * FROM inward 
where inwardID='$id'";
      $result = mysql_query($order);
      $row = mysql_fetch_array($result);
      ?>
      <form method="post" action="edit_data.php">
      <input type="hidden" name="id" value="<?php echo $row['inwardID']; ?>">



        <tr>        
          <td>Receipt No</td>
          <td>
            <input type="text" name="inreceiptno" size="20" value="<?php echo "$row[inreceiptno]"?>">
          </td>
        </tr>

        <tr>
          <td>Receipt Date</td>
          <td>
            <input type="text" name="inreceiptdt" size="40" value="<?php echo "$row[inreceiptdt]"?>">
          </td>
        </tr>


        <tr>
          <td>Sender Name</td>
          <td>
            <input type="text" name="sendername" size="40" value="<?php echo "$row[sendername]"?>">
          </td>
        </tr>

        <tr>
          <td>Sender Address</td>
          <td>
            <input type="text" name="senderaddress" size="40" value="<?php echo "$row[senderaddress]"?>">
          </td>
        </tr>

        <tr>
          <td>Subject</td>
          <td>
            <input type="text" name="insubject" size="40" value="<?php echo "$row[insubject]"?>">
          </td>
        </tr>

        <tr>
          <td>Accepted by</td>
          <td>
            <input type="text" name="inacceptedby" size="40" value="<?php echo "$row[inacceptedby]"?>">
          </td>
        </tr>

        <tr>
          <td>Receipt Mode</td>
          <td>
            <input type="text" name="inreceiptmode" size="40" value="<?php echo "$row[inreceiptmode]"?>">
          </td>
        </tr>

        <tr>
          <td>Remark For Action</td>
          <td>
            <input type="text" name="remark" size="40" value="<?php echo "$row[remark]"?>">
          </td>
        </tr>

        <tr>
          <td>Responsible Person</td>
          <td>
            <input type="text" name="person" size="40" value="<?php echo "$row[person]"?>">
          </td>
        </tr>

        <tr>
          <td>Compliance Due Date</td>
          <td>
            <input type="text" name="duedate" size="40" value="<?php echo "$row[duedate]"?>">
          </td>
        </tr>

        <tr>
          <td>Mode of Compliance Sent</td>
          <td>
            <input type="text" name="compliancemode" size="40" value="<?php echo "$row[compliancemode]"?>">
          </td>
        </tr>

        <tr>
          <td>Date of A.D.receipt ( If A.D.)</td>
          <td>
            <input type="text" name="adreceiptdate" size="40" value="<?php echo "$row[adreceiptdate]"?>">
          </td>
        </tr>

        <tr>
          <td>Name of the file for record</td>
          <td>
            <input type="text" name="filename" size="40" value="<?php echo "$row[filename]"?>">
          </td>
        </tr>

        <tr>
          <td align="right"> <input name="submit" type="submit" value="save">

          </td>
        </tr>
      </form>
            </table>

    </td>
  </tr>
</table>

//我的第三个文件是edit_data.php。代码是:

include "db.php";
if(isset($_POST['save']))
{   
    $inreceiptno= $_POST['inreceiptno'] ;                   
    $inreceiptdt=$_POST['inreceiptdt'] ;
    $sendername=$_POST['sendername'] ;
    $senderaddress=$_POST['senderaddress'] ;
    $insubject=$_POST['insubject'] ;
    $inacceptedby=$_POST['inacceptedby'] ;
    $inreceiptmode=$_POST['inreceiptmode'] ;
    $remark=$_POST['remark'];
    $person=$_POST['person'];
    $duedate=$_POST['duedate'];
    $compliancemode=$_POST['compliancemode'];
    $adreceiptdate=$_POST['adreceiptdate'];
    $filename=$_POST['filename'];



$order= "UPDATE inward SET inreceiptno='$inreceiptno',
                                    inreceiptdt='$inreceiptdt',
                                    sendername='$sendername',
                                    senderaddress='$senderaddress',
                                    insubject='$insubject',
                                    inacceptedby='$inacceptedby',
                                    inreceiptmode='$inreceiptmode',
                                    remark='$remark',
                                    person='$person',
                                    duedate='$duedate',
                                    compliancemode='$compliancemode',
                                    adreceiptdate='$adreceiptdate',
                                    filename='$filename'
            WHERE inwardID='$id'";
            }
            }
mysql_query($order);



header("location:edit.php");

?>

2 个答案:

答案 0 :(得分:0)

if(isset($_POST['save']))将其更改为:

,您的检查不正确
if(isset($_POST['submit']))

因为您没有任何名为save

的输入

答案 1 :(得分:0)

在edit_data.php中

变化

if(isset($_POST['save']))

if(isset($_POST['submit']))

并输入mysql_query($ order);在if语句中

更改代码

include "db.php";
if(isset($_POST['save']))
{   
    $inreceiptno= $_POST['inreceiptno'] ;                   
    $inreceiptdt=$_POST['inreceiptdt'] ;
    $sendername=$_POST['sendername'] ;
    $senderaddress=$_POST['senderaddress'] ;
    $insubject=$_POST['insubject'] ;
    $inacceptedby=$_POST['inacceptedby'] ;
    $inreceiptmode=$_POST['inreceiptmode'] ;
    $remark=$_POST['remark'];
    $person=$_POST['person'];
    $duedate=$_POST['duedate'];
    $compliancemode=$_POST['compliancemode'];
    $adreceiptdate=$_POST['adreceiptdate'];
    $filename=$_POST['filename'];



$order= "UPDATE inward SET inreceiptno='$inreceiptno',
                                    inreceiptdt='$inreceiptdt',
                                    sendername='$sendername',
                                    senderaddress='$senderaddress',
                                    insubject='$insubject',
                                    inacceptedby='$inacceptedby',
                                    inreceiptmode='$inreceiptmode',
                                    remark='$remark',
                                    person='$person',
                                    duedate='$duedate',
                                    compliancemode='$compliancemode',
                                    adreceiptdate='$adreceiptdate',
                                    filename='$filename'
            WHERE inwardID='$id'";
mysql_query($order);
            }
header("location:edit.php");

?>
相关问题