当我提交以下内容时,它不会出错,但它也不会将数据插入表中。我是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>
当我查看数据库表时,未插入记录。
答案 0 :(得分:1)
在查询'值[Sun Dec 13 18:17:32 2015] [debug] src/mod_auth_kerb.c(1944): [client
126.185.3.202] kerb_authenticate_user entered with user (NULL) and auth_type Kerberos
上,您输错了
原:
$_POST[pr]
固定:
$sql = "INSERT INTO student(Student,School,PR) VALUES ('$_POST[name]','$_POST[school]','$_POST[pr])";
mysqli_query($sql,$MySQLiconn);
答案 1 :(得分:1)
我发现了问题。
mysqli_query($sql,$MySQLiconn);
更改为
$sql = $MySQLiconn->query($sql);
感谢您的帮助。很高兴有人愿意教我这样的人。
答案 2 :(得分:0)
您的参数顺序错误;
mysqli_query($MySQLiconn,$sql);
应该是
$MySQLiconn->query($sql);
或如果你愿意,可以使用面向对象的方法
CREATE TABLE table_name ( dates ) AS
SELECT 201501 FROM DUAL
UNION ALL SELECT 201502 FROM DUAL
UNION ALL SELECT 201503 FROM DUAL
UNION ALL SELECT 201505 FROM DUAL
UNION ALL SELECT 201506 FROM DUAL
UNION ALL SELECT 201507 FROM DUAL
UNION ALL SELECT 201508 FROM DUAL
UNION ALL SELECT 201509 FROM DUAL
UNION ALL SELECT 201510 FROM DUAL
UNION ALL SELECT 201512 FROM DUAL
UNION ALL SELECT 201601 FROM DUAL
UNION ALL SELECT 201602 FROM DUAL