>"> Updat-6ren">
gpt4 book ai didi

php - 我可以使用一个执行两个操作的提交按钮吗?

转载 作者:行者123 更新时间:2023-11-30 01:18:15 26 4
gpt4 key购买 nike

这里是表单代码:

<?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" />&nbsp;<input type="text" name="c1"/><br/>
<input type="radio" name="answer" value="2"/>&nbsp;<input type="text" name="c2"/><br/>
<input type="radio" name="answer" value="3" />&nbsp;<input type="text" name="c3"/><br/>
<input type="radio" name="answer" value="4" />&nbsp;<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>

Updater.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 的同一页面,然后通过按下一个问题按钮我必须转到下一个问题(increment())有没有办法在同一个任务上执行两项任务按钮点击?

最佳答案

<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" />&nbsp;<input type="text" name="c1"/><br/>
<input type="radio" name="answer" value="2"/>&nbsp;<input type="text" name="c2"/><br/>
<input type="radio" name="answer" value="3" />&nbsp;<input type="text" name="c3"/><br/>
<input type="radio" name="answer" value="4" />&nbsp;<input type="text" name="c4"/><br/>
<input type="submit" name="submit" value="Next Question>>">
</form>

删除该嵌套表单。然后你必须确保回答问题的处理触发下一个问题代码。有效地完成您似乎要求的事情,而无需实际进行 2 个单独的操作。

关于php - 我可以使用一个执行两个操作的提交按钮吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18833689/

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