这是表单的代码:
<?php
include("updater.php");
if(isset($_POST['submit'])) {
increment(); //increments value of question no.(I don't want to use auto_increment hence this)
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Questions</title>
</head>
<body>
<form action="get_question.php" method="post">
<?php $q_no=$counter;
echo "Q.no.".$q_no ?><br/>
Question:<input type="text" name="question" cols="40" rows="3" /> <br/><br/>
<input type="radio" name="answer" value="1" /> <input type="text" name="c1"/><br/>
<input type="radio" name="answer" value="2"/> <input type="text" name="c2"/><br/>
<input type="radio" name="answer" value="3" /> <input type="text" name="c3"/><br/>
<input type="radio" name="answer" value="4" /> <input type="text" name="c4"/><br/>
<input type="submit" name="Submit" />
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Next Question>>">
</form>
</form>
更新程序.php:
<?php
$connection=mysql_connect("localhost","root","");
if(!$connection){
die("could not connect to database".mysql_error());
}
$select_db=mysql_select_db("oes",$connection);
if(!$select_db){
die("could not select database".mysql_error());
}
$result=mysql_query("SELECT q_no FROM counter WHERE ptr='here'");
$row= mysql_fetch_array($result);
$counter= $row["q_no"];
function increment(){
global $counter;
$counter++;
$updated=mysql_query("UPDATE oes.counter SET q_no = '$counter' WHERE counter.ptr ='here';");
return $counter;
}
function delete($q_no){
$action_delete1=mysql_query("DELETE FROM oes.questions WHERE q_no='$q_no';");
$action_delete2=mysql_query("DELETE FROM oes.choices WHERE q_no='$q_no';");
$action_adddeleted=mysql_query("INSERT INTO oes.deleted (q_no) VALUES ('$q_no');");
}
function use_delete(){
$retrive=mysql_query("SELECT MAX (q_no) AS q_no FROM deleted");
$action_delete=mysql_query("DELETE FROM oes.deleted WHERE q_no='$retrive';");
return $retrive;
}
?>
问题是提交按钮只是更新数据库中的问题,但给出具有相同 q_no 的同一页面,然后按下一个问题按钮我必须转到下一个(增量())有没有办法在同一个按钮单击时执行两个任务?