我正在尝试将表单输入发送到SQL数据库。单击提交后,它将进入空白页,并且不会将数据插入到我的表中。我对PHP相当陌生,认为这可能是语法错误,但是我不确定在哪里。
我已经研究了这个问题好几个小时,但没有一个解决方案对我有帮助。
HTML:
<form method="post" action="process.php">
<label>Name: </label>
<input type="text" id="name" />
<label>Email: </label>
<input type="email" id="email" />
<input type="submit" value="Submit" />
</form>
PHP:
<?php
$connect = mysqli_connect('localhost','root','','mydb');
if(mysqli_connect_errno()) {
echo "Failed to connect: " . mysqli_connect_error();
}
$name = mysqli_real_escape_string($connect,$_REQUEST[name]);
$email = mysqli_real_escape_string($connect,$_REQUEST[email]);
$sql = "INSERT INTO mytable (name, email) VALUES ('$name', '$email')";
if(mysqli_query($connect,$sql)) {
die('Error: ' . mysqli_error($connect));
} else {
echo "Submitted successfully";
}
mysqli_close($connect);
?>