尝试使用update语句编辑后数据库未更新

时间:2015-07-24 08:27:27

标签: php mysql

我的问题如下。我创建了一个从mysql数据库填充的表单。我希望能够在提交后编辑该表单。我已经达到了允许我编辑表单中的字段的程度,但是当我这样做时,数据不会在数据库上更新。你能看看我的代码,看看我可能会出错吗?

<?php
  include_once 'includes/db_connect.php';
?>

</head>
    <body>
      <table cellpadding="0" cellspacing="0">
      <tr>
        <td class="headingsa7">Acceptance Criteria</td>
        <td class="headingsa8">Technician Responsible</td>
     </tr>

     <tr>
      <td class="headings1">Job/Order Number:</td>
      <td class="answers1"><div class= "typesection1">
      <?php echo ($row['job_order_number'] ); ?></div></td>
    <tr>
      <td class="answersa7">
        <div class= "typesectiona7">
          <?php 
             echo   ($row['acceptance_criteria1'] );
          ?>
        </div>
     </td>

     <td class="answersa8">
        <div class= "typesectiona8">
            <?php 
                echo($row['technician_responsible1'] ); 
             ?>
        </div></td>
   </tr>

  <tr>
   <td class="answersa7">
   <div class= "typesectiona7">
     <?
       php echo ($row['acceptance_criteria2'] );
     ?>
   </div></td>

   <td class="answersa8">
      <div class= "typesectiona8">
         <?php 
            echo ($row['technician_responsible2'] ); 
         ?>
      </div>
    </td>
 </tr>
 <tr>
   <td class="answersa7">
       <div class= "typesectiona7">
         <?php 
            echo ($row['acceptance_criteria3'] ); 
         ?>
       </div>
 </td>
 <td class="answersa8">
      <div class= "typesectiona8">
         <?php 
            echo ($row['technician_responsible3'] ); 
         ?>
       </div>
    </td>
 </tr>
 <tr>
     <td class="answersa7">
          <div class= "typesectiona7">
               <?php 
                  echo($row['acceptance_criteria4'] ); 
               ?>
          </div>
    </td>
  <td class="answersa8">
         <div class= "typesectiona8">
             <?php
                echo($row['technician_responsible4'] );
              ?>
         </div>
       </td>
    </tr>
  </table>
     <br /><br />
        <center> 
          <?php echo "<a href=\"edit.php?  id=$row[job_order_number]\">Edit</a> |   <a href=\"delete.php?id=$row[job_order_number]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a> |
          ?>
       </center>
     </div>
    </body>
 </html>

编辑page.php

  </head>
       <body>
         <?php
                 mysql_connect("localhost","username","password");
                 mysql_select_db("joziweb1_form");
                 $order = "SELECT * FROM jobrequest";
                 $result = mysql_query($order);
                 $row = mysql_fetch_array($result);
           ?>
          <form method="post" action="edit_data.php">
               <table cellpadding="0" cellspacing="0">
                  <tr>
                     <td class="headingsa7">Acceptance Criteria</td>
                     <td class="headingsa8">Technician Responsible</td>
                  </tr>
                  <tr>
                     <td class="headings1">Job/Order Number:</td>
                     <td class="answers1">
                         <div class= "typesection1">
                            <?php 
                                echo $_GET['job_order_number'];
                             ?>
                          </div>
                     </td>
                 <tr>

                 <td class="answersa7">
                   <div class= "typesectiona7">
                          <?php 
                             echo ($row['acceptance_criteria1'] ); 
                          ?>
                   </div>
                 </td>
                  <td class="answersa8"><input class="typesectiona8" type="text" name="Technician_responsible1"value=<?php echo $technician_responsible1;?>> 
                 </td>
              </tr>
          <tr>
      <td class="answersa7">
            <div class= "typesectiona7">
                 <?php echo ($row['acceptance_criteria2'] ); ?>
            </div>
      </td>
    <td class="answersa8">

&GT;
                                                                   

     <td class="answersa8">

&GT;
                                                                                     &GT;
                                                              

Edit_data.php

    <?php 
       mysql_connect("localhost","username","password");
       mysql_select_db("databasename");           
       $order = "UPDATE jobrequest,
       SET technician_responsible1='$Technician_responsible1', technician_responsible2='$Technician_responsible2'                        technician_responsible3='$Technician_responsible3',                       technician_responsible4='$Technician_responsible4', 
       WHERE 'technician_responsible1' , 'technician_responsible2' , 'technician_responsible3' , 'technician_responsible4' , “;
      mysql_query($order);
      header("location:jobrequest_viewform.php");
  ?>

1 个答案:

答案 0 :(得分:4)

在edit.php页面中添加此代码

   session_start();
   $_SESSION['no']=$_GET['job_order_number'];

在edit_data.php中

   session_start();
   $no=$_SESSION['no'];

然后使用

   $order = "UPDATE jobrequest,
   SET technician_responsible1='$Technician_responsible1',technician_responsible2='$Technician_responsible2',technician_responsible3='$Technician_responsible3',technician_responsible4='$Technician_responsible4', 
   WHERE job_order_number='$no'“;
  mysql_query($order);

尝试这可能有效..