I am trying to update attribute's value
$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");
}
}
When i run it there is no error but the value of the attribute in my database has no update
Escape the variable to avoid SQL injection
$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 ");
As I understand you select something if equal to ID, so probably you ID in unique and you don't need while loop, if you need sorry :)
$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>";
Now if you want to make the post probably, I hope, you have a form somewhere, then you made the update
if (isset($_POST["submitbtn"]))
{
$Leave_Type = $_POST['Leave_Type'];
if($Leave_Type == 'Annual')
{
mysql_query("update `leave` set Status = 'Approved' where Leave_ID = '" . $lid . "'");
}
}