!doctype html>
<html>
<?php
$db = mysql_connect("localhost","root","root");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
}
$db_select = mysql_select_db("Quiz",$db);
if (!$db_select) {
die("Database selection also failed miserably: " . mysql_error());
}
?>
<head>
<meta charset="UTF-8">
<title>Quiz</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<form>
<?php
$result = mysql_query("SELECT * FROM `Questions`");
?>
<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<p class='question'>" . $row[1] . "</p>" . " <ul class='answers'>
<input type='radio' name='q1' value=" . $row[2] . "id='q1a'><label for='q1a'>" . $row[2] . "</label><br/> " . "<input type='radio' name='q1' value=" . $row[3] . "id='q1a'><label for='q1a'>" . $row[3] . "</label> <br/>" . "<input type='radio' name='q1' value=" . $row[4] . "id='q1a'><label for='q1a'>" . $row[4] . "</label><br/>" ."<input type='radio' name='q1' value=" . $row[5] . "id='q1a'><label for='q1a'>" . $row[5] . "</label><br/>
</ul> ";
}
mysql_free_result($result);
?>
<input type="submit" formaction="index.php" formmethod="post">
</form>
<?php
$answer = $_POST[q1];
mysql_query("INSERT INTO `User_Response`(`User_Response`) VALUES ('$answer')");
?>
</body>
</html>
我正在使用上面的代码,但是当我检查数据库时,与User_response相关的列为空,因为我设置为自动增加,它的ID只有一个增量。
我在这方面感到困惑,因为我一直在尝试,但我无法解决查询以使其工作。