简体   繁体   English

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

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

My code looks likes this: 我的代码如下所示:

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

In register.php file I have a database connection codes. 在register.php文件中,我有一个数据库连接代码。 I need to load another html page after submitting the form simultaneously if the database is connected through the register.php file. 如果数据库通过register.php文件连接,则在同时提交表单后,我需要加载另一个html页面。

How to do that? 怎么做?

Simply redirect the user to the second page once the registration is successful, through means of the header() function: 注册成功后,只需通过header()函数将用户重定向到第二页:

index.php: index.php:

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

register.php: register.php:

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

success.php: success.php:

// Thank the user for registering

Alternatively, you could always simply process your success page on register.php itself. 另外,您总是可以简单地在register.php本身上处理success页面。

Hope this helps! 希望这可以帮助! :) :)

Welcome to SO. 欢迎来到SO。 It sounds to me like you don't actually need to load 2 URLs simultaneously and what you are looking for is an if statement to execute some code only if post data is set 在我看来,您实际上不需要同时加载2个URL,而您要查找的是if语句,仅当设置了post数据时才执行一些代码

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

If you do need to make a request to 2 URLs at the same time you are looking for an AJAX request. 如果确实需要同时向2个URL发出请求,则正在寻找AJAX请求。

More detail in your question about your setup and end goal would be useful to help further. 有关您的设置和最终目标的问题中的更多详细信息将有助于进一步帮助。

in your Register.Php add something like this check your Sql result something like this 在您的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