【发布时间】:2012-10-31 23:44:15
【问题描述】:
我有一个 PHP 页面,它显示带有单选按钮的 MySQL 查询的总数。这是在一个表格里面。用户应该选择一个单选按钮来填写所有表格,然后总数将存储在数据库中,我想将所选单选按钮的总值传递到下一页并打印出来。
我知道这很容易,但我无法正确解决。
我的PHP页面代码如下:
<?php
session_start();
$Load=$_SESSION['login_user'];
include('../connect.php');
$sql= "Select name from student where ID='$Load'";
$username = mysql_query($sql);
$id=$_SESSION['login_user'];
if (isset($_POST['submit']))
{
$v1 = $_POST['v1'];
$v2 = intval($_POST['v2']);
$v3 = intval($_POST['v3']);
$v4 = intval($_POST['v4']);
$total = $2 + $v3 + $v4 ;
mysql_query("INSERT into Form1 (ID,P1,P2,P3,TOTAL)
values('$id','$v2','$v3','$v4','$total')") or die(mysql_error());
header("Location: mark.php");
}
?>
<html>
<head>
<?php
if(!isset($_SESSION['login_user']))
header("Location:index.html");
?>
<title>Q&A Form</title>
</head>
<body>
<center><form method="post" action="mark.php" >
<table style="width: 20%" >
<font size='4'>
<table style="width: 70%">
<tr>
<th > School Evaluation <font size="4" > </font></th>
<tr>
<th> Your attendance<font size="4" > </font></th>
<td> <input type="radio" name ="v2" value = "4" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v2" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v2" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v2" value = "1" onclick="updateTotal();" /></td>
</tr>
<tr>
<th > Your grades <font size="4" > </font></th>
<td> <input type="radio" name ="v3" value = "4" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v3" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v3" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v3" value = "1" onclick="updateTotal();" /></td>
</tr>
<tr>
<th >Your self-control <font size="4" > </font></th>
<td> <input type="radio" name ="v4" value = "4" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v4" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v4" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v4" value = "1" onclick="updateTotal();" /></td>
</tr>
</tr>
</table>
<br>
<td><input type="submit" name="submit" value="Submit">
<input type="reset" name="clear" value="clear" style="width: 70px"></td>
</form>
</center>
</div>
</body>
</html>
当用户按下提交时,所有无线电输入将存储在数据库中,并将转到 mark.php 我想在此页面中打印总和如何将总和传递到下一页?
【问题讨论】:
-
您可以在下一页从数据库中检索值,或将其保存在
$_SESSION -
或者你可以在重定向中传递它。 header("位置:mark.php?total=$total");
-
你能用代码解释一下吗?所以我能理解
-
但是您想在何时何地显示总数?用户提交表单后?
-
您的 php 中有一个错误,可能是由于复制/粘贴。这个
$total = $2 + $v3 + $v4 ;应该是$total = $v2 + $v3 + $v4 ;