PHP代码不会更新数据库

时间:2016-02-22 01:59:36

标签: php mysql database

我正在完成我的任务,但我无法让我的更新与我的数据库一起工作。 这是我保存数据的表单。

<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
?>

使用它时没有错误,它不会更新我的数据库,而是返回相关的项目页面。

1 个答案:

答案 0 :(得分:0)

这解决了问题

  

$ _ POST ['projectID']不在表格中 - Dagon