状态更新错误(空字段)

时间:2010-03-21 19:53:30

标签: php mysql

海人...... 我有一个问题,我无法恢复...... 我有一个表格,管理员需要批准或拒绝预订请求... 我已将表用法中的b_status字段设置为IN PROCESS默认值... 我想在用户点击APPROVE按钮时更新b_status值BOOKING APPROVED。 否则,当用户点击REJECT按钮时,b_status会将值更新为BOOKING REJECTED

这是表单代码:

<?php
     $db = mysql_connect('localhost','root') 
     or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

    $sql="SELECT * FROM vehicle WHERE v_status='READY'";

     $result = mysql_query($sql) or die ("Query failed!");  
 ?>
 <tr><td>&nbsp;</td></tr>
  <tr>
  <tr>
    <td width="200"><font face="Arial" size="2" font color="#000000">Registration Number </font></td>
    <td><select name="regno">
            <option value="" selected>--Registration No--</option>
            <?php while($row = mysql_fetch_array($result)){?>
            <option value="<?php echo $row['regno']; ?>"><?php echo $row['regno']; ?></option>
            <?php } ?>
        </select></td>
    <td><font face="Arial" size="2" font color="#000000">Reason</font></td>
  <td><textarea name="reason" rows="3" cols="50 "value = ""></textarea></td>
  </tr>
  <?php
     $db = mysql_connect('localhost','root') 
     or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

    $sql="SELECT * FROM driver WHERE d_status='READY'";

     $result = mysql_query($sql) or die ("Query failed!");  
 ?>
  <tr>
    <td><font face="Arial" size="2" font color="#000000">Driver</font></td>
    <td><select id = "d_name" name="d_name">
      <option value="" selected>--Driver Name--</option>
      <?php while($row = mysql_fetch_array($result)){?>
      <option value="<?php echo $row['d_name']; ?>"><?php echo $row['d_name']; ?></option>
      <?php } ?>
    </select></td>
  </tr>
  <tr>
<?php                    
      mysql_close($db);
?>

</table>
<p></p>

<center><input name="APPROVED" type="submit" id="APPROVED" value="APPROVED"> 
<input name="REJECT" type="submit" id="REJECT" value="REJECT"> </center>

      </div>
    </center>

这是流程页面代码:

<?php
     $db = mysql_connect('localhost','root') 
     or die ("unable to connect");
     mysql_select_db('fyp',$db)
     or die ("able to select");

    $bookingno=mysql_real_escape_string($_POST['bookingno']);
    $username=mysql_real_escape_string($_POST['username']);
    $name=mysql_real_escape_string($_POST['name']);
    $department=mysql_real_escape_string($_POST['department']);
    $g_date=mysql_real_escape_string($_POST['g_date']);
    $g_time=mysql_real_escape_string($_POST['g_time']);
    $r_date=mysql_real_escape_string($_POST['r_date']);
    $r_time=mysql_real_escape_string($_POST['r_time']);
    $destination=mysql_real_escape_string($_POST['destination']);
    $pass_num=mysql_real_escape_string($_POST['pass_num']);
    $trip_purpose=mysql_real_escape_string($_POST['trip_purpose']);
    $regno=mysql_real_escape_string($_POST['regno']);
    $d_name=mysql_real_escape_string($_POST['d_name']);
    $reason=mysql_real_escape_string($_POST['reason']);
    $b_status=mysql_real_escape_string($_POST['b_status']);


$sql = "INSERT INTO `usage` VALUES('$bookingno','$username','$name','$department','$g_date','$g_time','$r_date','$r_time','$destination', '$pass_num','$trip_purpose','$regno','$d_name','$reason','$b_status')";

                $query = "INSERT INTO `usage` VALUES b_status ='BOOKING APPROVED'";
                $result = @mysql_query($query);

                $query1 = "UPDATE driver SET d_status ='OUT' WHERE '$d_name'=d_name";
                $result1 = @mysql_query($query1);

if(isset($_POST['APPROVED']))
        {

            $query2 = "UPDATE `usage` SET b_status ='BOOKING APPROVED' WHERE '$b_status'='IN PROCESS'";
                $result2 = @mysql_query($query2);

        }


if (isset($_POST['REJECT']))
        {

            $query3 = "UPDATE `usage` SET b_status ='BOOKING REJECTED' WHERE '$b_status'='IN PROCESS'";
                $result3 = @mysql_query($query3);

        }



//$result = mysql_query($sql) or die ("error!");
$result = mysql_query($sql) or trigger_error (mysql_error().' in '.$sql); 

我在b_status字段上遇到了问题.. PLZ伙计们...... 帮帮我: - )

1 个答案:

答案 0 :(得分:1)

您没有检查查询是否实际成功。将您的代码更改为以下内容:

$query = "INSERT INTO `usage` VALUES b_status ='BOOKING APPROVED'";
$result = @mysql_query($query);

if (mysql_error()) {
     die("Database error: " . mysql_error());
}

如果您有正确的错误检查,您会看到您的INSERT查询格式错误。它应写成如下:

INSERT INTO `usage` (b_status) VALUES ('BOOKING APPROVED');

从不认为查询会成功,并且总是在调用mysql_query()之后检查mysql_error()。即使查询本身在语法上是正确的,它也可能因任何其他原因而失败。