一直试图从各种教程中学习如何创建用户输入表单并使用php发送到mysql。我最终从不同的来源学习代码的不同部分,并且经常在将它们组合在一起时发现这个错误。
我想我理解每个部分正在做什么,并且看不到任何语法错误,但毫无疑问它在某个地方是错误的......
请帮助它让我发疯(关于表格和安全mysqli的完整教程的任何建议,谢谢)
<?php # DISPLAY COMPLETE REGISTRATION PAGE.
# Set page title and display header section.
$page_title = 'mysqli_form2' ;
# Check form submitted.
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' );
{
# Connect to the database.
require ('../connect_db.php');
// Escape user inputs for security
$first_name = mysqli_real_escape_string($link, $_POST['first_name']);
$last_name = mysqli_real_escape_string($link, $_POST['last_name']);
$email_address = mysqli_real_escape_string($link, $_POST['email']);
// attempt insert query execution
$sql = "INSERT INTO mysql_test (first_name, last_name, email_address)VALUES('$first_name', '$last_name', '$email')";
if(mysqli_query($link, $sql))
{
echo "success.";
}
else
{
echo "ERROR: not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
<!-- Display body section with sticky form. -->
<h1>stu's test form...</h1>
<form action="mysqli_form2.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20"
value="<?php if (isset($_POST['first_name'])) echo POST['first_name'];?">
<p>Last Name: <input type="text" name="last_name" size="20"
value="<?php if (isset($_POST['last_name'])) echo$_POST['last_name'];?"></p>
<p><input type="submit" value="GO...."></p>
</form>