【发布时间】:2013-11-18 01:14:36
【问题描述】:
我有一个要求安全问题和答案的表单,提交后数据被输入到我的 SQL 数据库中,但由于某种原因,当我运行表单并尝试打印显示的数据以确保正确输入时数据是空白的,所以我检查了 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>
【问题讨论】:
-
这需要基本的调试。
$sQuestion是否包含值? (这里的问题是你没有给你的表单元素一个name属性,虽然) -
sql-server 标记是指微软制造的特定关系型数据库,而不是您使用的 mysql。你的mysql代码也是vulnerable to injection和using an obsolete API。最后,当PHP生成一个空白页面而不是做某事时,你需要enable error reporting。
标签: php html mysql sql sql-server