得到一个我的查询为空的响应


getting a response that my Query was empty

当我在更新页面上运行下面的更新命令时,我得到一个空的查询结果,这是我在脚本上的更新命令,我已经编辑并提供了完整的代码

     <?php
error_reporting(E_ALL ^ E_DEPRECATED);
$connect = mysql_connect("localhost", "root", "tert") or die(mysql_error());
mysql_select_db("ub", $connect) or die(mysql_error());
if(isset($_POST['status']))
{
    $sql = "UPDATE admin SET Status = '".$_POST['status']."'
    WHERE Status = '".$_POST['status']."'
     ";
    $query = mysql_query($sql) or die(mysql_error());
}


?>
<table width = "70%" cellpadding = "5" cellspace = "5" >
<div class="row-fluid">
        <div class="span6">
            <table class="table table-responsive">
            <thead>

            <tr>
<td><strong> Last Name </td>
<td><strong> First Name </td>
<td><strong> Staff Id </td>
<td><strong> Status</td>

</tr>
<?php 
while($row = mysql_fetch_array($query)) { ?>
<tr> 
<td> <?php echo $row['lName']; ?> </td>
<td> <?php echo $row['fName']; ?> </td>
<td> <?php echo $row['staffId']; ?> </td>
<td><div contenteditable> <?php echo $row['Status']; ?> </td>

</tr>

<?php 
}
?>

thanks lot in advance

这样修改查询:

 $sql = "UPDATE admin SET Status = '".$row['Status']."' WHERE Status = '".$row['Status']."'";

什么是$row[Status] ?你是说$row['Status']吗?

请输入PDO

好吧,我认为你没有得到查询的原因是你定义了你的$sql在你的if()条件,一旦循环退出,$sql查询变成空的,所以我认为你应该把$查询在你的if条件,让你得到一个结果集。你的If循环像这样

if(isset($_POST['status']))
{
    $sql = "UPDATE admin SET Status = '".$row['Status']."'
    WHERE Status = '".$row['Status']."'
     ";
    $query = mysql_query($sql) or die(mysql_error());
}