編輯一個mysql主題所以我創建這個CMS的教師信息作爲我的論文的一部分。當我需要創建/刪除主題時,我的代碼似乎工作正常。但是,當我嘗試更新它們時,它告訴我編輯過程失敗。不知道究竟在哪裏出錯。無法使用Php
以下是我的主題查詢。我有點新的PHP,所以如果我犯了一些明顯的錯誤,請耐心等待。
if (isset($_POST['submit']))
{
//form was submitted
$staff_id = mysql_real_escape_string((int) $_POST["staff_id"]);
$first_name = mysql_real_escape_string($_POST["first_name"]);
$last_name = mysql_real_escape_string($_POST["last_name"]);
$age = mysql_real_escape_string((int) $_POST["age"]);
$email = mysql_real_escape_string($_POST["email"]);
$phone_no = mysql_real_escape_string((int) $_POST["phone_no"]);
$department = mysql_real_escape_string($_POST["department"]);
$visible = mysql_real_escape_string((int) $_POST["visible"]);
$message = "Your details have been received";
//Database Query
$query = "UPDATE subjects SET ";
$query .= "first_name = '{$first_name}', ";
$query .= "last_name = '{$last_name}', ";
$query .= "age = '{$age}', ";
$query .= "email = '{$email}', ";
$query .= "phone_no = '{$phone_no}', ";
$query .= "department = '{$department}', ";
$query .= "visible = '{$visible}', ";
$query .= "WHERE staff_id = '{$staff_id}', ";
$query .= "LIMIT 1";
$result = mysqli_query($connect, $query);
if($result && mysqli_affected_rows($connect) == 1)
{
//Success
echo "Subject Edited. ";
}
else
{
//failure
echo "Subject Editing failed. ";
}
}
,這是這是我們用來發送數據進行編輯
<form action="editsub.php" method ="post">
<p>Staff ID to edit:
<input type="number" name="staff_id" value ="" />
</p>
<p>First Name:
<input type="text" name="first_name" value ="" />
</p>
<p>Last Name:
<input type="text" name="last_name" value ="" />
</p>
<p>Age:
<input type="number" name="age" value ="" />
</p>
<p>E-mail:
<input type="text" name="email" value ="" />
</p>
<p>Phone Number:
<input type="number" name="phone_no" value ="" />
</p>
<p>Department:
<input type="text" name="department" value ="" />
</p>
<p>Visible:
<input type="radio" name="visible" value ="0" /> No
<input type="radio" name="visible" value ="1" /> Yes
</p>
<input type="submit" name="submit" value="Edit Entry" />
</form>
因此,如果有人能指出其中的錯誤是我會非常感激的形式。感謝
錯誤報告踢出了什麼? http://us1.php.net/manual/en/mysqli.error.php('echo mysqli_error($ connect);') – LuckySpoon
你在where子句中有一個不必要的逗號。 –
@AnonySterling你應該添加這個答案而不是評論。 (好眼睛:)) –