0
我有一個PHP頁面,顯示單選按鈕的MySQL查詢總數。這是在一個表單內。用戶應該選擇一個單選按鈕來填寫所有表單,然後總數將被存儲在數據庫中,我想將選定的單選按鈕的總值傳遞到下一頁並打印出來。PHP - 將單選按鈕的總價值傳遞到下一頁
我知道這是一個容易的,但我不能正確的解決方案。
我對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(「Location:mark.php?total = $ total」); – qooplmao
你可以用代碼解釋嗎?所以我可以理解 – user1806136