尝试更新输出没有错误但没有工作

时间:2013-08-29 15:27:47

标签: php mysql sql

我正在尝试更新属性的值

$lid        = $_GET["id"];
$check_user = mysql_query("select employee.Emp_Name, leave.Leave_Type from `leave`, employee where leave.Leave_ID = $lid AND leave.Emp_ID = employee.Emp_ID ");
while($rows = mysql_fetch_assoc($check_user))
{
    echo "<td>: </td>";
    echo "<td>". $rows['Leave_Type']."</td>";
    echo "</tr>";
    echo "<td>: </td>";
    echo "<td>". $rows['Emp_Name']."</td>";
    echo "</tr>";
}

if (isset($_POST["submitbtn"]))
{
    if($rows['Leave_Type'] == 'Annual')
    {
        mysql_query("update `leave` set Status = 'Approved' where Leave_ID = $lid");        
    }
}

当我运行它时没有错误,但我的数据库中的属性值没有更新

1 个答案:

答案 0 :(得分:0)

转义变量以避免SQL注入

$lid        = $_GET["id"];
$check_user = mysql_query("select employee.Emp_Name, leave.Leave_Type from `leave`, employee where leave.Leave_ID = '" . $lid . "' AND leave.Emp_ID = employee.Emp_ID ");

据我所知你选择的东西如果等于ID,那么你的ID可能是唯一的,你不需要while循环,如果你需要抱歉:)

$rows = mysql_fetch_assoc($check_user));

    echo "<td>: </td>";
    echo "<td>". $rows['Leave_Type']."</td>";
    echo "</tr>";
    echo "<td>: </td>";
    echo "<td>". $rows['Emp_Name']."</td>";
    echo "</tr>";

现在,如果您想要发布帖子,我希望,您在某个地方有一个表单,然后您进行了更新

if (isset($_POST["submitbtn"]))
{
    $Leave_Type = $_POST['Leave_Type'];

    if($Leave_Type == 'Annual')
    {
        mysql_query("update `leave` set Status = 'Approved' where Leave_ID = '" . $lid . "'");        
    }
}