1

我正在尝试使用的表单有两个按钮: 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" />

我要做的是在用户点击提交按钮时运行查询。知道怎么做吗?

4

4 回答 4

1

我通常做的只是点击一个按钮更改表单的目的地,然后提交。例如:

<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,并为一致性起见将它们绑定 - 由您决定。

于 2013-09-12T04:04:46.430 回答
0

您需要跟踪名为“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";
        }
    }
?>

希望对您有所帮助。

于 2013-09-12T04:30:29.447 回答
0

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
}
于 2013-09-12T04:10:10.183 回答
0

您可以将“编辑”设置为普通按钮,而不是提交类型。并将点击事件绑定到它,它可以重定向到可编辑表单或使表单可编辑(最适合您)。然后“reg”提交可以像当前一样工作以保存数据。

于 2013-09-12T06:04:38.797 回答