gpt4 book ai didi

php - 将html属性值传递给php中的下一个脚本

转载 作者:搜寻专家 更新时间:2023-10-31 21:38:19 24 4
gpt4 key购买 nike

我有三个 PHP 脚本。 main.php questions.php 和 values.php

这是代码

ma​​in.php

<html>
<head>
<title></title>
</head>

<body>
<h1>Be Prepare for the battle</h1>
<?php
$strTitle = "Begin";
$strLink = "<a href = 'question.php?ques_id=1'>" . $strTitle ."</a>";
echo $strLink;
?>
</body>
</html>

问题.php

<?php
require_once('../connect.php');
$quesSQL = mysql_query("SELECT * FROM `questions` WHERE `ques_id`=". $_GET["ques_id"]);

if(!mysql_num_rows($quesSQL) >= 1)
{
die('Complete.');
}

$next = $_GET["ques_id"];

while($row = mysql_fetch_array($quesSQL)) {
$id = $row['ques_id'];
$strTitle = $row['ques_title'];
echo "<li>" . $strTitle . "</li><br/>";
}

$optSQL = mysql_query("SELECT `options`,`values` FROM questions_options WHERE " . $id . "= ques_id");
echo "<form action=\"values.php\" method=\"POST\">";

while($row = mysql_fetch_array($optSQL) ) {
$strOptions = $row['options'];
$strValues = $row['values'];
echo "<input type =\"radio\" name =\"valueIn\" value=" . $strValues . " />" . $strOptions . "<br/>";
}
echo "</form>";
$strTitle = "<input type =\"submit\" value=\"Next\">";
$next = $next + 1;
$strLink = "<a href = 'values.php?ques_id=" . $next . "'>" . $strTitle ."</a>";
echo $strLink;

mysql_close();
?>

values.php

<?php
require_once('../connect.php');
$input = $_POST['valueIn'];
$ansSQL = mysql_query("SELECT `answer` FROM questions WHERE 1-".$_GET["ques_id"]."= ques_id");

$marks = 0;
if($input == $ansSQL)
{
$marks = $marks+1;
}
else
{
$marks = $marks+0;
}
echo $marks;
?>

现在的问题是我必须将一个值从第二个脚本 (questions.php) 传递到第三个脚本 (values.php)。它来自单选按钮名称值“valueIn”中的

部分。但我不能那样做。因为我在第二个脚本的末尾发送了另一个值 ques_id 和 $strLink 变量。那我该怎么做呢?

最佳答案

我不确定您为什么使用链接来处理表单中可能包含的内容。正如 anusha 所述,您应该像这样为 ques_id 使用隐藏的输入字段

问题.php

<?php
require_once('../connect.php');
$quesSQL = mysql_query("SELECT * FROM `questions` WHERE `ques_id`=". $_GET["ques_id"]);

if(!mysql_num_rows($quesSQL) >= 1)
{
die('Complete.');
}

$next = $_GET["ques_id"];

while($row = mysql_fetch_array($quesSQL)) {
$id = $row['ques_id'];
$strTitle = $row['ques_title'];
echo "<li>" . $strTitle . "</li><br/>";
}

$optSQL = mysql_query("SELECT `options`,`values` FROM questions_options WHERE " . $id . "= ques_id");
echo "<form action=\"values.php\" method=\"POST\">";

while($row = mysql_fetch_array($optSQL) ) {
$strOptions = $row['options'];
$strValues = $row['values'];
echo "<input type =\"radio\" name =\"valueIn\" value=" . $strValues . " />" . $strOptions . "<br/>";
}

$next = $next + 1;
$strLink = '<input type="hidden" name="ques_id" value="'.$next.'">';
echo $strLink;

$strTitle = "<input type =\"submit\" value=\"Next\">";
echo $strTitle;
echo "</form>";

mysql_close();
?>

然后在下一步中通过 $_POST 可以使用这两个变量,如下所示

$input = $_POST['valueIn'];
$ques_id = $_POST['ques_id'];

关于php - 将html属性值传递给php中的下一个脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13945837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com