我正在尝试工作的表单有两个按钮:1:用于查看提交的信息和2:用于保存确认的信息。
我的部分表格:
$sql="INSERT INTO applicant_information
(entrepreneur_name,enterprise_name,.....) values
('".$_POST['entrepreneur_name']."','".$_POST['enterprise_name']."','".$_POST['address']."'...)
<form method="post" action="business_form.php">
<table width="70%" cellspacing="2px" cellpadding="5px"style="border:1px solid black;border-collapse:collapse;">
<th colspan="8"align="left" style="border:1px solid black;"><b>Personal
Information</th>
<tr>
<td width="18" rowspan="2" style="border:1px solid black;">1</td>
<td width="142" rowspan="2"style="border:1px solid black;" >Name</td>
<td style="border:1px solid black;" colspan="2">Entrepreneur</td>
<td colspan="2"style="border:1px solid black;"><?php echo $_POST['entrepreneur_name']?>
<input id="entrepreneur_name" name="entrepreneur_name" type="hidden" value="<?php echo $_POST['entrepreneur_name']?>" />
</td>
</tr>.....
//rest of the form
<input type="submit" name="edit" style="width:10%"value="Back to edit" />
<input type="submit" name="reg"style="width:10%"value="Submit" />
我正在尝试做的是在用户点击提交按钮时运行查询。知道怎么做吗?
我通常做的只是让一个按钮在单击时更改表单的目的地,然后提交它。所以例如:
<form action="login.php" method="POST" id="myform">
<input name="username">
<input type="password" name="password">
<input type="submit" value="Login">
<button id="js-register">Register</button>
</form>
跟
$('#js-register').click(function() {
$('#myform').attr('action', 'register.php').submit();
});
或者你可以让两个按钮都是Javascript的,为了一致性而绑定它们 - 由你决定。
HTML
<form action="handle_user.php" method="POST />
<input type="submit" value="View" name="view" />
<input type="submit" value="Submit" name="submit">
</form>
按以下方式检查 php 中的条件...
if($_POST["view"]) {
//User hit the view button, handle accordingly
}
if($_POST["submit"]) {
//User hit the Submit information , handle accordingly
}
您需要跟踪名为"reg"的按钮。因此,在$sql
字符串之后,您可以放置以下内容:
<?php
if (isset($_POST['reg'])) {
mysql_query($sql);
if (mysql_affected_rows() > 0) {
echo "REgistration completed";
}
else {
echo "System could not process the registration";
}
}
?>
希望对您有所帮助。
您可以将"编辑"设置为普通按钮,而不是提交类型。并将单击事件绑定到它,该事件可以重定向到可编辑的表单或使表单可编辑(最适合您)。然后,"reg"提交可以像当前一样工作以保存数据。