如何解决错误消息?我尝试在您的 INSERT 语句中使用反引号 ` 代替,但仍然不起作用 [重复]

问题描述 投票:0回答:0

我该如何解决

Fatal error: Uncaught mysqli_sql_exception: 你的SQL语法有错误;查看与您的 MariaDB 服务器版本对应的手册,了解在 'INSERST INTO parent....

附近使用的正确语法

我在这句话中收到一条错误消息 --> mysqli_query($conn, $query);

<?php
$conn = mysqli_connect('localhost','root','','capstone') or die(mysqli_error());

if (isset($_POST["login"])) {
    $username = $_POST["username"];
    $firstname = $_POST["firstname"];
    $lastname = $_POST["lastname"];
    $school_id = $_POST["school_id"];
    $class_id = $_POST["class_id"];
    $password = $_POST["password"];
    $cpassword = $_POST["cpassword"];
    $duplicate = mysqli_query($conn, "SELECT * FROM student WHERE username = '$username'");
    if (mysqli_num_rows($duplicate) > 0) {
        echo
        "<script> alert ('Username has Already Taken');</script>";
    } else {
        if ($password == $cpassword) {
            $query = "INSERT INTO student('student_id','firstname', 'lastname', 'school_id', 'class_id', 'username', 'password','status') VALUES ('','$firstname,'$lastname','$school_id','$class_id','$username','$password','')";
            mysqli_query($conn, $query);
            echo
            "<script> alert ('Registration Successful');</script>";
        }
        else{
        echo
        "<script> alert ('Password Does not match');</script>";
        }
    }
}
?>
<form id="signin_student" class="form-signin" method="post">
    <h3 class="form-signin-heading"><i class="icon-lock"></i> Sign up as Student</h3>
    <input type="text" class="input-block-level" id="username" name="username" placeholder="Username" required>
    <input type="text" class="input-block-level" id="firstname" name="firstname" placeholder="Firstname" required>
    <input type="text" class="input-block-level" id="lastname" name="lastname" placeholder="Lastname" required>
    <label>School</label>
    <select name="school_id" class="input-block-level span5">
        <option></option>
        <?php
        $query = mysqli_query($conn, "select * from school order by school_name ")or die(mysqli_error());
        while ($row = mysqli_fetch_array($query)) {
            ?>
            <option value="<?php echo $row['school_id']; ?>"><?php echo $row['school_name']; ?></option>
            <?php
        }
        ?>
    </select>
    <label>Class</label>
    <select name="class_id" class="input-block-level span5">
        <option></option>
        <?php
        $query = mysqli_query($conn, "select * from class order by class_name ")or die(mysqli_error());
        while ($row = mysqli_fetch_array($query)) {
            ?>
            <option value="<?php echo $row['class_id']; ?>"><?php echo $row['class_name']; ?></option>
            <?php
        }
        ?>
    </select>
    <input type="password" class="input-block-level" id="password" name="password" placeholder="Password" required>
    <input type="password" class="input-block-level" id="cpassword" name="cpassword" placeholder="Re-type Password" required>
    <button id="signin" name="login" class="btn btn-info" type="submit"><i class="icon-check icon-large"></i> Sign in</button>
</form>

<a onclick="window.location = 'index.php'" id="btn_login" name="login" class="btn" type="submit"><i class="icon-signin icon-large"></i> Click here to Login</a>

我检查表名和数据库一样。

php html mysqli
© www.soinside.com 2019 - 2024. All rights reserved.