[英]How can I post form into same php page and intercept it?
I'm trying to submit a form to same page, so I want submit data, and then save into DB... And then update my page with new data... 我正在尝试将表单提交到同一页面,所以我想提交数据,然后保存到数据库中...然后用新数据更新我的页面...
I do it in this way: 我这样做:
<?php
if (isset($_POST["matricola"]) && isset($_POST["pc"])){
echo "QUI";
$conn = dbConnect($USERDB, $PASSWORDDB, $NAMEDB); //seleziono il database e mi connetto
$matricola = $_POST['matricola'];
$pc = $_POST['pc'];
$queryGetUser = "select id from user where matricola = ".$matricola;
$user = dbQueryGetResult($queryGetUser);
$today = getdate();
$data = $today['mday']."/".$today['month']."/".$today['year'];
$ora = $today['hours'].":".$today['minutes'].":".$today['seconds'];
$sql = "insert into utelenza (id_user, id_pc, dataEntrata, oraEntrata) values (".$user[0].", ".$pc.", ".$data.", ".$ora.")";
dbQueryInsert($sql);
}
//Prendo dal DB le note del laboratorio visualizzabili da tutti
$conn = dbConnect($USERDB, $PASSWORDDB, $NAMEDB);
$queryGetNoteLab = "select noteLaboratorio from laboratorio where id_laboratorio = " . $IDLAB;
$notaLab = dbQueryGetResult($queryGetNoteLab);
$queryGetInfoLab = "select info150ore from laboratorio where id_laboratorio = " . $IDLAB;
$infoLab = dbQueryGetResult($queryGetInfoLab);
$queryGetPcs = "select * from pc where id_laboratorio = " . $IDLAB;
$pcs = dbQueryReturnMatrix($queryGetPcs);
dbDisconnect($conn);
echo "<form action='home150.php' method='post'>"
. "<table><tr><td>Matricola</td><td><input id='matricola' type='text' ></td></tr>"
. "<tr><td>PC</td><td><select id='pc'><option value=''></option>";
for ($i = 0; $i < count($pcs); $i++) {
echo "<option value=" . $pcs[$i][0] . ">" . $pcs[$i][2] . "</option>";
}
echo "</select></td></tr></table>"
. "<input id='submitButton' type='submit' value='Inserisci'></form>";
?>
The form submitted, but after submit I can't intercept the data post.. 表单已提交,但是提交后我无法拦截数据发布。
Why?? 为什么?? How can I fix it?? 我该如何解决?
Thank you! 谢谢!
change your form like this if you want to submit form in same page then no need to give form action
give submit button a name and use isset
in php code for button's submit 像这样更改表单,如果您想在同一页面中提交表单,则无需给form action
提供提交按钮的名称,并在php代码中使用isset
进行按钮的提交
<form action='' method='post'>"
<table>
<tr>
<td>Matricola</td>
<td>
<input id='matricola' type='text'>
</td>
</tr>
<tr>
<td>PC</td>
<td>
<select id='pc'>
<option value=''></option>
<?php for ($i=0 ; $i < count($pcs); $i++) {?>
<option value="<?php echo $pcs[$i][0]?>">
<?php echo $pcs[$i][2]?>
</option>
<?php }?>
</select>
</td>
</tr>
</table>
<input id='submitButton' type='submit' value='Inserisci' name="submit">
</form>
<?php if(isset($_POST['submit']))
{
//your query for insert or whatever
}?>
You should give names to all your inputs. 您应该为所有输入名称。 eg the submit button. 例如提交按钮。
<input type='submit' name='submit' value='Inserisci'>
Then in your code above it. 然后在上面的代码中。
if(isset($_POST['submit'])){
//check values of form
}
Change action to nothing, it will call itself then. 将动作更改为空,然后它将自行调用。
<form action='' method='post'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.