<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dentalclinic") or die(mysql_error());
if (isset($_POST['update'])){
$UpdateQuery = "UPDATE appointment SET appointmentstatusid='$_POST[appointmentstatusid]'";
mysql_query($UpdateQuery);
};
$sql = "SELECT * from appointment a join appointmentstatus s on (a.appointmentstatusid=s.appointmentstatusid) join patient p on (a.patientid=p.patientid)";
$query = mysql_query($sql) or die(mysql_error());
echo "<table border=1>
<tr>
<th>FIRST NAME</th>
<th>LAST NAME</th>
<th>APPOINTMENT STATUS</th>
<th>UPDATE</th>
</tr>";
while($record = mysql_fetch_array($query)){
echo "<form action=editstatus.php method=post>";
echo "<tr>";
echo "<td>"."<input type=text name=firstname value=".$record['firstname']."></td>";
echo "<td>"."<input type=text name=lastname value=".$record['lastname']."></td>";
echo "<td>";
$query2 = "SELECT * from appointmentstatus";
$result = mysql_query($query2);
echo "<select name=appointmentstatusid>";
while ($line = mysql_fetch_array($result)) {
echo "<option value=".$line['appointmentstatusid'].">";
echo $line['appointmentstatus'];
echo "</option>";
}
echo "</select>";
echo "</td>";
echo "<td>"."<input type=submit name=update value=update"."></td>";
echo "</tr>";
echo "</form>";
}
echo "</table>"
?>
每當我更新patient1的appointmentstatusid,它會影響其他患者(patient2,patient3 ...)的約會狀態。我嘗試在更新中添加代碼WHERE appointmentstatusid='$_POST[appointmentstatusid]'
,但是當我這樣做時,它不會再更新。如何更新特定行(患者)?
嘗試$ UpdateQuery =「更新約會SET appointmentstatusid ='{$ _ POST ['appointmentstatusid']}'」; –
不要再使用'mysql_ *'函數,因爲它們在當前版本的PHP中被取消了。改用「PDO」或「mysqli」。 – TiMESPLiNTER
@SyedQarib的結果是一樣的。它會更新一切。 –