我有这个表格要求提供安全问题和答案,并在提交后将数据输入我的SQL DB但由于某种原因我运行表单并尝试打印显示的数据以确保输入正确数据是空白的,所以我检查SQL数据库,有一个新的条目,但它都是空白的。
我正在试图弄清楚为什么表单没有将任何数据输入SQL DB。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form method="post" id="myForm" name="input" action="submitSQL.php">
Security Question: <input type="text" id="sQuestion" ></br>
Security Question Answer: <input type="text" id="sqAnswer" ></br>
</br>
<input type="submit">
</form>
</body>
</html>
PHP文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$sQuestion = filter_input(INPUT_POST, 'sQuestion');
$sqAnswer = filter_input(INPUT_POST, 'sqAnswer');
$conn = mysql_connect("localhost","root","")or die (mysql_error());
mysql_select_db("assignment_3", $conn);
$insert = "insert into securityquestiontable (securityQuestion, securityAnswer) values('$sqAnswer', '$sQuestion')";
$result = mysql_query($insert, $conn) or die (mysql_error());
print "<table border=1>
<tr><td>Security Question:</td><td> '$sQuestion'</td></tr></br>
<tr><td>Security Question Answer:</td> <td> '$sqAnswer'</td></tr></br>
</table>";
?>
</body>
</html>
答案 0 :(得分:0)
您尚未为字段指定name
个属性。
此:
Security Question: <input type="text" id="sQuestion" ></br>
Security Question Answer: <input type="text" id="sqAnswer" ></br>
应该是这样的:
Security Question: <input type="text" id="sQuestion" name="sQuestion"></br>
Security Question Answer: <input type="text" id="sqAnswer" name="sqAnswer"></br>