使用准备好的语句更新失败,错误不清楚

时间:2018-10-12 08:51:26

标签: php html mysql

因此,我对这个php和mysqli还是一个新手,现在仍在一点一点地学习,在尝试使用准备好的语句来更新数据以避免SQL注入时遇到的常见问题,我遇到了麻烦。我不清楚我在哪里犯了错误,但是我知道我的数据没有更新,因为每次我按下更新按钮时,它只会将我重定向回我的编辑表单页面。

所以,这是我的edit-job-post.php

<form action="editpost.php">
    <?php
        $sql = "SELECT * FROM job_post WHERE id_jobpost='$_GET[id]'";
        $result = $conn->query($sql);
        if($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
    ?>
    <div class ="col-md-12 latest-job">
            <div class="form-group">
            <label for="jobtitle" type="text" id="jobtitle" >Job Title </label>  
            <input name="ic_no"type="text" class="form-control input-lg" value="<?php echo $row['jobtitle'] ?>" >   
            </div>

            <div class="form-group">
            <label for="description" type="text" id="description" >Description </label>  
            <textarea id="description" name="description" class="form-control"><?php echo $row['description']; ?></textarea>
            </div>

            <div class="form-group">
            <label for="typeofjob" type="text" id="typeofjob" >Type of Job </label>  
            <input type="text" class="form-control  input-lg" id="typeofjob" value="<?php echo $row['typeofjob']?>">
            </div>

            <div class="form-group">
            <label for="salary" type="text" id="salary" >Salary Offered </label>
            <input type="number" class="form-control  input-lg" id="salary" name="salary" value="<?php echo $row['salary']?>">
            </div>

        <div class="form-group">
            <label for="qualification" type="text" id="qualification" >Qualification Required </label>
            <input type="text" class="form-control  input-lg" id="qualification" name="qualification" value="<?php echo $row['qualification']?>">
        </div>

        <div class="form-group">
            <button type="submit" class="btn btn-flat btn-success">Update</button>
        </div>
    </div>
    <?php
            }
        }
   ?>
</form>

这是我的editpost.php

<?php
session_start();

if(empty ($_SESSION['id_admin'])){
    header("Location:../index.php");
    exit();
}
    require_once("../db.php");



    if (isset($_POST['submit'])) {     


        $sql = $conn->prepare("UPDATE job_post SET jobtitle=? , description=? , typeofjob=?, salary=?, qualification=?  WHERE id_jobpost=?");

        $jobtitle = mysqli_real_escape_string($conn, $_POST['jobtitle']);
        $description = mysqli_real_escape_string($conn, $_POST['description']);
        $typeofjob = mysqli_real_escape_string($conn, $_POST['typeofjob']);
        $salary = mysqli_real_escape_string($conn, $_POST['salary']);
        $qualification = mysqli_real_escape_string($conn, $_POST['qualification']);


        $sql->bind_param("sssssi",$jobtitle, $description, $typeofjob, $salary, $qualification, $_GET["id_jobpost"]);    

        if($sql->execute()) {
            $_SESSION['jobEditSuccess'] = true;
            header("Location: dashboard.php");

        } else {

            echo "ERROR";
        }

    }
    else{
        header("Location:create-job-post.php");
        exit();
    }


?>

我已阅读此处发布的几个问题,这些问题可能会为我提供解决方案

  1. Unable to update mysql table

  2. Can't update mysql database using php

  3. Can't update my edit form

等等。我知道我的问题是重复的,但是由于我一直在阅读并且没有找到解决方法,所以我确实需要知道答案。预先感谢您的所有帮助。

0 个答案:

没有答案