我工作我的任務,我無法讓我的更新與我的數據庫一起工作。 這是我的表格,它包含數據。PHP代碼不會更新數據庫
<form name="edit" method="post" action="process/editRecord.php">
<p class="indent">
<label for="projectName">Edit Project Name</label>
<input type="text" name="projectName" id="projectName" value="<?php echo $projectName; ?>">
</p>
<p class="indent">
<label for="projectSoftware">Edit Project Software</label>
<input type="text" name="projectSoftware" id="projectSoftware" value="<?php echo $projectSoftware; ?>" >
</p>
<p class="indent">
<label for="projectDescription">Edit Project Description</label>
<textarea name="projectDescription" id="projectDescription" cols="150" rows="10" ><?php echo $projectDescription; ?></textarea>
</p>
<p class="indent">
<label for="projectImage">Edit Project Image</label>
<input type="text" name="projectImage" id="projectImage" value="<?php echo $projectImage; ?>" >
</p>
<p class="indent">
<label for="projectInformation">Edit Project Information</label>
<textarea name="projectInformation" id="projectInformation" cols="400" rows="10" ><?php echo $projectInformation; ?></textarea>
</p>
<p>
<input type="submit" name="button" id="button" value="Update">
</p>
</form>
然後就是這個過程。
<?php
ini_set('display_errors', 1);
require('../../includes/conn.inc.php');
require('../../includes/functions.inc.php');
// sanitize user variables
$sprojectName = safeString($_POST['projectName']);
$sprojectSoftware = safeString($_POST['projectSoftware']);
$sprojectDescription = safeString($_POST['projectDescription']);
$sprojectImage = safeString($_POST['projectImage']);
$sprojectInformation = safeString($_POST['projectInformation']);
$sprojectID = safeInt($_POST['projectID']);
// prepare SQL
$stmt = $mysqli->prepare("UPDATE projects SET projectName =?, projectSoftware =?, projectDescription=?, projectImage =?, projectInformation =? WHERE projectID = ?");
$stmt->bind_param('sssssi', $sprojectName, $sprojectSoftware, $sprojectDescription, $sprojectImage, $sprojectInformation, $sprojectID);
$stmt->execute();
$stmt->close();
header("Location: ../../php/projects.php");
// redirect browser
exit; // make sure no other code executed
?>
使用此項時我不會遇到任何錯誤,它不會更新我的數據庫,但會返回到相關項目頁面。
到底是什麼'safeString()'函數?只使用準備好的陳述。你看不到任何錯誤消息,因爲很可能你沒有打開它,因爲你沒有檢查是否實際執行了語句 – Ghost
safeString正在清理它,所以你不能sql注入它,準備什麼國家代碼 –
這個準備好的語句:'$ mysqli-> prepare(...',參見[PHP:MySQLi>快速入門指南>準備語句](http://docs.php.net/manual/en/mysqli.quickstart。 prepared-statements.php) – VolkerK