我想使用多个页面为表单编写测验,值名称,电子邮件,城市和土地不能保存在数据库中,但表单应保存所有值。
这是表格的第一页: page1.php中
<fieldset>
<legend>Personendaten</legend>
<div>
<label for="Name" accesskey="U">Name</label>
<input name="Name" type="text" id="Name" placeholder="Namen eingeben" required />
</div>
<div>
<label for="E-Mail" accesskey="E">E-Mail</label>
<input name="E-Mail" type="text" id="E-Mail" placeholder="E-Mail" required /> </div>
<label for="Stadt">Stadt</label>
<input name="Stadt" type="text" id="Stadt" placeholder="test2" required />
<div>
<label for="Land">Land</label>
<input name="Land" type="text" id="Land" placeholder="test" required />
</div>
</fieldset>
<fieldset>
<input type="submit" name="submit" />
</form>
表单的第二页 使page2.php
<?php
$name = $_POST['Name'];
$email = $_POST["E-Mail"];
$stadt = $_POST["Stadt"];
$land = $_POST["Land"];
?>
<html>
<head></head>
<body>
<form method="post" action="page3.php">
<input type="hidden" name="Name" value="<?php $name;?>" />
<input type="hidden" name="E-Mail" value="<?php $email;?>" />
<input type="hidden" name="Stadt" value="<?php $stadt;?>" />
<input type="hidden" name="Land" value="<?php $land;?>" />
<input type="radio" name="rb1" value="a1" required > radiobutton1<br>
<input type="radio" name="rb1" value="a2"> a2<br>
<input type="radio" name="rb1" value="a3" required > a3<br>
<input type="radio" name="rb1" value="a4"> a4<br>
<input type="radio" name="rb2" value="b1" required > a1<br>
<input type="radio" name="rb2" value="b2"> a2<br>
<input type="radio" name="rb2" value="b3" required > a3<br>
<input type="radio" name="rb2" value="b4"> a4<br>
<input type="radio" name="rb3" value="c1" required > a1<br>
<input type="radio" name="rb3" value="c2"> a2<br>
<input type="radio" name="rb3" value="c3" required > a3<br>
<input type="radio" name="rb3" value="c4"> a4<br>
<input type="radio" name="rb4" value="d1" required > a1<br>
<input type="radio" name="rb4" value="d2"> a2<br>
<input type="radio" name="rb4" value="d3" required > a3<br>
<input type="radio" name="rb4" value="d4"> a4<br>
<input type="radio" name="rb5" value="d1" required > a1<br>
<input type="radio" name="rb5" value="d2"> a2<br>
<input type="radio" name="rb5" value="d3" required > a3<br>
<input type="radio" name="rb5" value="d4"> a4<br>
<input type="radio" name="rb6" value="e1" required > a1<br>
<input type="radio" name="rb6" value="e2"> a2<br>
<input type="radio" name="rb6" value="e3" required > a3<br>
<input type="radio" name="rb6" value="e4"> a4<br>
<input type="radio" name="rb7" value="f1" required > a1<br>
<input type="radio" name="rb7" value="f2"> a2<br>
<input type="radio" name="rb7" value="f3" required > a3<br>
<input type="radio" name="rb7" value="f4"> a4<br>
<input type="radio" name="rb8" value="g1" required > a1<br>
<input type="radio" name="rb8" value="g2"> a2<br>
<input type="radio" name="rb8" value="g3" required > a3<br>
<input type="radio" name="rb8" value="g4"> a4<br>
<br> <br>
<input type="submit" name="submit" />
</form>
</body>
</html>
表单处理程序页面 page3.php
<?php
include 'dbconfig.php';
if (isset($_POST['submit']))
{
$name = $_POST["Name"];
$email = $_POST["E-Mail"];
$stadt = $_POST["Stadt"];
$land = $_POST["Land"];
$rb1 = $_POST["rb1"];
$rb2 = $_POST["rb2"];
$rb3 = $_POST["rb3"];
$rb4 = $_POST["rb4"];
$rb5 = $_POST["rb5"];
$rb6 = $_POST["rb6"];
$rb7 = $_POST["rb7"];
$rb8 = $_POST["rb8"];
echo "Successfully submitted\n";
echo("\n");
$score = 0;
if($rb1 == "a1") {
$score++;
} else if($rb1 == "a2") {
$score--;
}
else if($rb1 == "a3") {
$score--;
}
else if($rb1 == "a4") {
$score--;
}
if($rb2 == "b1") {
$score++;
} else if($rb2 == "b2") {
$score--;
}
else if($rb2 == "b3") {
$score--;
}
else if($rb2 == "b4") {
$score--;
}
if($rb3 == "c1") {
$score++;
} else if($rb3 == "c2") {
$score--;
}
else if($rb3 == "c3") {
$score--;
}
else if($rb3 == "c4") {
$score--;
}
if($rb4 == "d1") {
$score++;
} else if($rb4 == "d2") {
$score--;
}
else if($rb4 == "d3") {
$score--;
}
else if($rb4 == "d4") {
$score--;
}
if($rb5 == "e1") {
$score++;
} else if($rb5 == "e2") {
$score--;
}
else if($rb5 == "e3") {
$score--;
}
else if($rb5 == "e4") {
$score--;
}
if($rb6 == "f1") {
$score++;
} else if($rb6 == "f2") {
$score--;
}
else if($rb6 == "f3") {
$score--;
}
else if($rb6 == "f4") {
$score--;
}
if($rb7 == "g1") {
$score++;
} else if($rb7 == "g2") {
$score--;
}
else if($rb7 == "g3") {
$score--;
}
else if($rb7 == "g4") {
$score--;
}
if($rb8 == "h1") {
$score++;
} else if($rb8 == "h2") {
$score--;
}
else if($rb == "h3") {
$score--;
}
else if($rb8 == "h4") {
$score--;
}
$query = "INSERT INTO wertetest VALUES ('$name', '$email',
'$stadt', '$land', '$rb1', '$rb2', '$rb3', '$rb4',
'$rb5', '$rb6', '$rb7', '$rb8', '$score')";
mysql_query($query) or die(mysql_error());
header ("refresh:50;url=http://link.com");
}
?>
db的页面: dbconfig.php
<?php
//Define your host here.
$hostname = "localhost";
//Define your database username here.
$username = "root";
//Define your database password here.
$password = "+++++++";
//Define your database name here.
$dbname = "dbtest1";
$conn = mysql_connect($hostname, $username, $password);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
?>