无法通过PHP将新记录插入到mysql数据库中

前端之家收集整理的这篇文章主要介绍了无法通过PHP将新记录插入到mysql数据库中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我按下提交按钮时,我收到错误.

object not found error.

页面自动添加带有自动递增主键的空条目(无需按下提交按钮).

我仍然是PHP的初学者,我彻底搜索,但我无法找到代码中的错误.

<html>   
<head>
    <title>Add New Record in MysqL Database</title>
</head>   
<body>
    <form action="insert.PHP" method="post">
        <p>

            <label for="Name">Full Name:</label>

            <input type="text" name="Name" id="Name">

        </p>
        <p>
            <label for="Code">Code:</label>
            <input type="text" name="Code" id="Code">
        </p>
        <p>
            <label for="GPA">GPA:</label>
            <input type="text" name="GPA" id="GPA">
        </p>
        <input type="submit" value="Submit">
    </form>

    <?PHP
 /* Attempt MysqL server connection. Assuming you are running MysqL

 server with default setting (user 'root' with no password) */

 $link = MysqLi_connect("localhost","username","password","students");
// Check connection

if ($link === false) {

die("ERROR: Could not connect. " . MysqLi_connect_error());
}
// Escape user inputs for security
$full_name = filter_input(INPUT_POST,'full_name');
$code = filter_input(INPUT_POST,'code');
$gpa = filter_input(INPUT_POST,'gpa');
// attempt insert query execution
$sql = "INSERT INTO info VALUES ('$full_name','$code','$gpa')";
if (MysqLi_query($link,$sql)) {
 echo "Records added successfully. $full_name";
} else {
 echo "ERROR: Could not able to execute $sql. " . MysqLi_error($link);
}
// close connection
MysqLi_close($link);
?>
</body>
</html>
试试这个:
$full_name = filter_input(INPUT_POST,'Name');
$code = filter_input(INPUT_POST,'Code');
$gpa = filter_input(INPUT_POST,'GPA');

我写这个的原因是因为你的输入名称包含Name,Code和GPA所以你需要把它写成输入名称(区分大小写).

原文链接:https://www.f2er.com/php/138498.html

猜你在找的PHP相关文章