我正在基于PHP脚本创建调查。该脚本会重新加载自己的一组不同的视频以及一组单选按钮,以便在单击"提交"之后进行选择。按钮。
我遇到的问题是我的分数没有保存在Session变量中。当我打印它时,它是空的。
以下是我的代码的摘录:
<?php
session_start();
if (isset($_POST['submit2'])) {
$_SESSION['rating2'] = $_POST['score2'];
}
?>
<table>
<tr>
<td>
<?PHP echo "<embed src='$video1' width='400' height='400'>"; ?>
<br/><br/>
<input type="radio" name="score2" value="A"> <?php echo "A"; ?>
</td>
<td>
<?PHP echo "<embed src='$video2' width='400' height='400'>"; ?>
<br/><br/>
<input type="radio" name="score2" value="B"> <?php echo "B"; ?>
</td>
</tr>
</table>
<form action="setup2.php?video=<?php echo $nextvideo; ?>" method="post">
<input type="submit" name="submit2" value="Submit">
道歉,如果看起来很混乱,我对PHP很陌生,并希望有人能指出我正确的方向。谢谢!
答案 0 :(得分:1)
将您的收音机拉入表格
<form action="setup2.php?video=<?php echo $nextvideo; ?>" method="post">
<input type="submit" name="submit2" value="Submit">
<input type="radio" name="score2" value="A"> <?php echo "A"; ?>
</td>
<td>
<?PHP echo "<embed src='$video2' width='400' height='400'>"; ?>
<br/><br/>
<input type="radio" name="score2" value="B"> <?php echo "B"; ?>
</form>
答案 1 :(得分:0)
我不确定你为什么称它为“得分&#39;因为你要保存Chars - 但这是我期望它做的事情:
<?php
session_start();
if (isset($_POST['submit2'])) {
$_SESSION['rating2'] = $_POST['score2'];
}
?>
<form action="setup2.php?video=<?php echo $nextvideo; ?>" method="post">
<table>
<tr>
<td>
<?PHP echo "<embed src='$video1' width='400' height='400'>"; ?>
<br/><br/>
<input type="radio" name="score2" value="A"> <?php echo "A"; ?>
</td>
<td>
<?PHP echo "<embed src='$video2' width='400' height='400'>"; ?>
<br/><br/>
<input type="radio" name="score2" value="B"> <?php echo "B"; ?>
</td>
</tr>
</table>
<input type="submit" name="submit2" value="Submit">
</form>