当我按下提交按钮时,我收到错误.
原文链接:https://www.f2er.com/php/138498.htmlobject 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>