为什么赢了';我的变量不会在每一页上传递吗?Php
我无法让变量“quick\u name”通过几页来进行测验。“quick\u name”变量作为$\u POST[]从question\u menu.php发送到question\u created.php以处理question\u created.php后,假设php将该变量发送回question\u menu.php。我做错了什么。老实说,我认为我的做法是错误的 改写: QUITY_name=“如何得分篮”作为$u POST['QUITY_name']提交到question_menu.php。然后以$\u POST['quick\u name']的形式提交到quick\u created.php,然后提交回question\u menu.php 我收到一个变量quick\u name undefined错误,它被发送回quesion\u菜单 coach_quizzes.php为什么赢了';我的变量不会在每一页上传递吗?Php,php,variables,post,session-variables,Php,Variables,Post,Session Variables,我无法让变量“quick\u name”通过几页来进行测验。“quick\u name”变量作为$\u POST[]从question\u menu.php发送到question\u created.php以处理question\u created.php后,假设php将该变量发送回question\u menu.php。我做错了什么。老实说,我认为我的做法是错误的 改写: QUITY_name=“如何得分篮”作为$u POST['QUITY_name']提交到question_menu.php
<head>
<title>Your Quizzes</title>
</head>
<body>
<h1> Current Quizzes </h1>
<form name="submit_button" action="create-quiz.php">
<input type="submit" value="Create Quiz">
</form>
</body>
</html>
你的测验
当前测验
提交至->创建_quick.php
<?php session_start()
?>
<head>
<title>Your Quizzes</title>
</head>
<body>
<h1> Enter Quiz Name </h1>
<form action="questions_menu(test).php" method="post">
<input type="text" name="quiz_name" maxlength="30" size="30">
<input type="submit" value="Create Quiz">
</form>
</body>
</html>
你的测验
输入测验名称
输入:“如何得分”然后提交至question_menu.php
<!DOCTYPE html>
<html>
<head>
<title>Add Question</title>
<link rel="stylesheet" type="text/css" href="css/info_style.css" />
</head>
<body>
<div id="main">
<header>
<div id="welcome">
<h2>Prairie View A&M University</h2>
</div><!--close welcome-->
</header>
<div id="site_content">
<form enctype="multipart/form-data" method="post" action="quiz_created.php">
<table border="0" name"form_table">
<tr>
<td>Quiz Name</td>
<td><?php echo $_POST['quiz_name']?></td>
</tr>
<tr>
<td>Question</td>
<td><textarea name="description" rows="4" cols="50"></textarea></td>
</tr>
<tr>
<td>Option 1</td>
<td><input type="text" name="option1" maxlength="30" size="30"></td>
</tr>
<tr>
<td>Option 2</td>
<td> <input type="text" name="option2" maxlength="30" size="30"></td>
</tr>
<tr>
<td>Option 3</td>
<td><input type="text" name="option3" maxlength="30" size="30"></td>
</tr>
<tr>
<td>Answer</td>
<td>
<select name="dropdown">
<option value='option1'>Option 1</option>
<option value='option2'>Option 2</option>
<option value='option3'>Option 3</option>
</select>
</td>
</tr>
<tr>
<td>Image</td>
<td><input type="file" name="file" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="10000" /><br>
</td>
</tr>
<tr>
<td colspan="2"><p>
<input type="submit" value="Add Question">
</p></td>
</tr>
</table>
</form>
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = "coach_john";
$con = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MYsql");
//echo "Connected to mysql<br>";
mysql_select_db("$database")
or die("Could not select Basketball_database");
//echo "Connected to database";
//update when update button pressed
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE $table SET question_description='$_POST[description]', option_a='$_POST[option1]', option_b='$_POST[option2]', option_c='$_POST[option3]', answer='$_POST[dropdown]', question_id='$_POST[questionID]' WHERE question_id='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};//end of if statement
//delete when delete button pressed
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM $table WHERE question_id='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};//end of if statement
$mysql = "SELECT * FROM $table";
$mydata = mysql_query($mysql,$con);
//create table
echo "<table border=1
<tr>
<th>Question ID</th>
<th>Quiz Name</th>
<th>Question Description</th>
<th>Option 1</th>
<th>Option 2</th>
<th>Option 3</th>
<th>Answer</th>
<th>Picture</th>
</tr>";
//insert data into rows
while($records = mysql_fetch_array($mydata)){
echo "<form action=questions_menu(test).php method=post>";
echo "<tr>";
echo "<td>"."<input type=text name=questionID size=5 value=".$records['question_id']." </td>";
echo "<td>"."<input type=text name=option1 size=18 value=".$records['quiz_name']." </td>";
echo "<td>"."<textarea name=description rows=1 cols=25>".$records['question_description']."</textarea>"."</td>";
echo "<td>"."<input type=text name=option1 size=18 value=".$records['option_a']." </td>";
echo "<td>"."<input type=text name=option2 size=15 value=".$records['option_b']." </td>";
echo "<td>"."<input type=text name=option3 size= 15 value=".$records['option_c']." </td>";
echo "<td>"."<input type=text name=answer size=15 value=".$records['answer']." </td>";
echo "<td>". $records['image'] ." </td>";
echo "<td>"."<input type=hidden name=hidden value=".$records['question_id']." </td>";
//update button
echo "<td>"."<input type=submit name=update value=Update onclick='return confirm(\"Are you sure you want to update question?\")'>"." </td>";
//delete button
echo "<td>"."<input type=submit name=delete value=Delete onclick='return confirm(\"Are you sure you want to delete question?\")'>"." </td>";
echo "</tr>";
echo "</form>";//end form
} echo "</table>";
mysql_close();
?> <!-- End of php code-->
</div><!--close site_content-->
<footer>
<a href="test folder/index.html">Home</a> | <a href="test folder/ourwork.html">Photos</a> | <a href="test folder/testimonials.html">Videos</a> | <a href="test folder/projects.html">Schedule</a> | <a href="test folder/contact.html">Contact</a><br/><br/>
</footer>
</div><!--close main-->
</body>
</html>
添加问题
草原景观A&;M大学
测验名称
问题
选择1
选择2
选择3
答复
选择1
选择2
选择3
形象
我看到了很多问题,但其中一个问题是您没有正确地逃避php插入
echo "<td>"."<input type=text name=questionID size=5 value=".$records['question_id']." </td>";
一个主要问题是您试图将原始POST数据设置到数据库中。这是一个巨大的安全漏洞。其他问题,如php的其余部分,与引号、双引号、分号等有关。。。仔细阅读语法。你的整个脚本基本上都错了。我不熟悉PHP、MYSQL和HTML,我知道我会有很多缺陷。我将阅读更多关于语法的内容,并尽我所知修改我所有的语法缺陷。我正在尝试创建一个测验应用程序,但这一部分阻碍了我。
echo "<td>"."<input type=text name=questionID size=5 value=".$records['question_id']." </td>";
echo '<td><input type="text" name="questionID" size="5" value="'.$records['question_id'].'" /></td>';
$UpdateQuery = "UPDATE $table SET question_description='$_POST[description]', option_a='$_POST[option1]', option_b='$_POST[option2]', option_c='$_POST[option3]', answer='$_POST[dropdown]', question_id='$_POST[questionID]' WHERE question_id='$_POST[hidden]'";