PHP同时运行两个脚本


PHP running 2 scripts at the same time

我希望你能帮忙。我是PHP的新手,它让我抓狂!

我有一个html文档,里面有单独的登录和注册表格。每一个都有自己的php脚本来注册或登录。当测试登录表单或注册表单的输入错误消息时,它似乎同时运行了两个脚本,并且我得到了这两个脚本的错误消息。

我花了今天的大部分时间试图找到解决方案,但没有成功。有没有一种方法可以为每个脚本定义一个名称,这样我就可以为引用特定php脚本的每个表单标记添加一个操作?

或者这是一种使用php-if-else语句的方法,基于按下哪个html按钮?

提前感谢

无望编码器

或者这是一种使用php-if-else语句的方法,基于该语句html按钮被按下?

是的,假设你有

<input type='submit' name='subbtn' value='Register'>
...
<input type='submit' name='subbtn' value='Log In'>

然后在php:中

if ($_REQUEST['subbtn'] == 'Register') {
  // they pressed register
} else {
  // they pressed log in (or some other submit button)
}

您可以将隐藏元素附加到post方法

<input type="hidden" name="type" value="login">

<input type="hidden" name="type" value="register">

以上内容应分别采用不同的形式。

在PHP页面

<?
     if($_POST['type'] == "login") {
       // continue login operation
     } else {
       // do registration
     }
?>

当然有一种方法可以将它们分离成两个文件,然后分别调用操作。

<form action="registration.php">
...
</form>
<form action="login.php">
...
</form>

或者有另一种方法可以在一个文档中完成

<form action="" method="POST">
...
<input type="submit" name="btn_register">
</form>
<form action="" method="POST">
...
<input type="submit" name="btn_login">
</form>
<?php
if(isset($_POST['btn_register'])) {
    //Do the stuff with registration
}
if(isset($_POST['btn_login'])) {
    //Do the stuff with login
}
?>