我正在php和html的帮助下创建一份问题文件,每个问题都有最少4个选项,每个选项都存储在数据库中。现在我在一个部分感到困惑,我想添加一个按钮,为该问题添加更多选项(每次点击该按钮时有更多文本字段),并且这些选项应该包含在该表中。我试图尝试,但没有成功。
这是我的代码:
<?php
if(isset($_POST['submit'])){
include('dbconfig.php');
$part=$_POST['part'];
$que=$_POST['Que'];
$ans1=$_POST['first'];
$ans2=$_POST['second'];
$ans3=$_POST['third'];
$ans4=$_POST['fourth'];
$ans5=$_POST['fifth'];
$ans6=$_POST['sixth'];
$right=$_POST['right'];
$marks=$_POST['marks'];
$tablename=$_REQUEST['table'];
$query="INSERT INTO `tomarproject`.`$tablename` (`qid`, `part`, `Ques`, `firstans`, `secans`, `thirdans`, `fourthans`, `fifthans`, `sixthans`, `RightAns`,`marks`) VALUES (NULL, '$part', '$que', '$ans1', '$ans2', '$ans3', '$ans4', '$ans5', '$ans6', '$right','$marks');";
mysql_query($query) or die(mysql_error());
$query = mysql_insert_id();
echo $query;
}
else{
if(isset($_POST['finish']))
{
$message = "Exam Created succesfully!";
header("location:manageexam.php?logout=$message");
}
}
?
>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin |ExamPaper Page</title>
<style>
body{
margin:0 0;
font-family:Tahoma, Geneva, sans-serif;
font-size:12px;
color:#036;
background-color:#CCC}
.wraper{
background-color:#FFF;
margin:0 auto;
width:800px;
border-left:1px solid #666;
border-right:1px solid #666;
height:auto;
padding:10px;}
ul{
margin:0 0;}
ul li{
list-style:none;
}
.header{
margin-bottom:10px;}
</style>
</head>
<body>
<!--text editor.-->
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">tinymce.init({
selector: "textarea",
// ===========================================
// INCLUDE THE PLUGIN
// ===========================================
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste jbimages"
],
// ===========================================
// PUT PLUGIN'S BUTTON on the toolbar
// ===========================================
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
// ===========================================
// SET RELATIVE_URLS to FALSE (This is required for images to display properly)
// ===========================================
relative_urls: false
});</script>
<?php
$table= $_REQUEST['table'];
include('dbconfig.php');
$query = mysql_query("SELECT * FROM $table");
$numrows = mysql_num_rows($query);
?>
<div class="wraper">
<div class="header"><h1>Create Question for Subject: "<?php echo $_REQUEST['table'];?>"</h1> | Total No. of Questions: <?php echo $numrows;?> | <strong>Total Marks</strong>
<?php
if(isset($marks))
{
$totalmarks = mysql_query("INSERT INTO examsmeta ('TotalMarks') VALUES ('$marks')");
$lastvalue = mysql_query("SELECT * FROM $table ORDER BY marks ASC") or die('error in query');
$row=mysql_fetch_assoc($query);
echo "Exam Meta: ", $row['marks'];
echo " New Marks: ", $marks;
}
else
echo 0;
?>
</div>
<ul><form action="feedque.php?table=<?php echo $_REQUEST['table'];?>" method="post">
<br>
Part:<input type="text" name="part"/><br>
Question:<textarea id="textarea1" name="Que"></textarea>
<li>1.<textarea class="input" name="first"></textarea></li>
<li>2.<textarea class="input" name="second"></textarea></li>
<li>3.<textarea class="input" name="third"></textarea></li>
<li>4.<textarea class="input" name="fourth"></textarea></li><br />
<input type="submit" name="add" value="Add Options" />
<?php if(isset($_POST['add']))
{ ?>
<textarea class="input" name=""></textarea>
<?php } ?>
<li>
Right Option: <select name="right">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</li>
<li>Marks for this Question:<input type="text" name="marks"/></li>
<li><input type="submit" value="Submit" name="submit" /></li>
<li><input type="submit" value="Finish" name="finish" /></li>
</form></ul>
</div>
</body>
</html>
请通过这些帮助我,任何帮助都会得到赞赏谢谢。