【发布时间】:2014-08-06 22:27:56
【问题描述】:
每个问题都有 3 个答案,在数据库中分配的分数为 0、1 或 2。
如何保存每个带有问题 ID 的答案和带有名称和电子邮件的答案 ID? 使用此脚本显示的数据库中的问题行中大约有 50 个问题:
<?php
include "config.php";
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Testar uppkoppling:
if (mysqli_connect_errno()){
// Databaskoppling error
exit("Couldn't connect to the database: ".mysqli_connect_error());
}
$result = mysqli_query($db,"SELECT * FROM que");
echo '<form action="taemot.php" method="post" id="MyForm">';
while($row = mysqli_fetch_array($result)) {
echo '' . $row['que_question'] . '
<input type="radio" name="' . $row['que_answer0'] . '" value="' . $row['que_answer0'] . '">
<input type="radio" name="' . $row['que_answer1'] . '" value="' . $row['que_answer1'] . '">
<input type="radio" name="' . $row['que_answer2'] . '" value="' . $row['que_answer2'] . '"><br>';
}
echo ' <input type="text" name="name" value="Namn"><br>
<input type="text" name = "email" value="Epostadress"><br>
<input type="submit" value="Submit"> </form>';
?>
taemot.php
<?
$name=$_POST['name'];
$email=$_POST['email'];
mysql_connect("XXXX", "XXXX", "XXXX")
or die(mysql_error()); mysql_select_db("database") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email')");
Print "Your information has been successfully added to the database."; ?>
【问题讨论】: