当我提交下面的数据时,它不会出错,但也不会将数据插入到表中。我是一个php初学者,所以请宽恕我。

<?php
/* include_once 'dbconn.php';*/
include 'menu.php';
error_reporting(0);
?>
<head></head>
<body>
    <form action="add_student.php" method="post">
        Name:<input type="text" name="name"><br/>
        School:<input type="text" name="school"><br/>
        PR:<input type="text" name="pr"><br/>
        <input type="submit" name="submit">
    </form>
<?php
$DB_host = "localhost";
$DB_user = "root";
$DB_pass = "root";
$DB_name = "trackmeet";

$MySQLiconn = new MySQLi($DB_host,$DB_user,$DB_pass,$DB_name);

if($MySQLiconn->connect_errno)
{
    die("ERROR : -> ".$MySQLiconn->connect_error);
}

if (isset($_POST['submit'])){
    $sql = "INSERT INTO student(Student,School,PR) VALUES ('$_POST[name]','$_POST[school]','$_POST[pr])";
    mysqli_query($sql,$MySQLiconn);
    mysqli_close($MySQLiconn);
}
?>

</body>
</html>

当我在数据库表中查找时,没有插入记录。

最佳答案

我发现了问题。

mysqli_query($sql,$MySQLiconn);

更改为
$sql = $MySQLiconn->query($sql);

谢谢你的帮助很高兴有人愿意教我这样的人。

07-26 00:15
查看更多