繁体   English   中英

用户单击提交按钮时如何调用两个不同的网页?

[英]How to call two different webpages when the user clicks submit button?

我的代码如下所示:

<form action="register.php" method="post">
  <input type="text" name="uname">
  <input type="submit" >
</form>

在register.php文件中,我有一个数据库连接代码。 如果数据库通过register.php文件连接,则在同时提交表单后,我需要加载另一个html页面。

怎么做?

注册成功后,只需通过header()函数将用户重定向到第二页:

index.php:

<form action="register.php" method="post">
  <input type="text" name="uname">
  <input type="submit" >
</form>

register.php:

// Process registration
if (valid) {
  header('success.php);
}

success.php:

// Thank the user for registering

另外,您总是可以简单地在register.php本身上处理success页面。

希望这可以帮助! :)

欢迎来到SO。 在我看来,您实际上不需要同时加载2个URL,而您要查找的是if语句,仅当设置了post数据时才执行一些代码

if(!empty($_POST)){
  //code to execute when form is submitted
}
else {
  //code to execute otherwise
}

如果确实需要同时向2个URL发出请求,则正在寻找AJAX请求。

有关您的设置和最终目标的问题中的更多详细信息将有助于进一步帮助。

在您的Register.Php添加类似这样的内容检查您的Sql结果类似这样的内容

$sql='select * Tablename where condition'

$result= fetch($sql)
$row=fetch_array($result)asdsad
if($row>0){
header(Location:'connected.php') // whatever your html
}
else {header(Location:"failed.php")//whenever query got no row
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM