Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向HTML提交按钮添加链接_Php_Html - Fatal编程技术网

Php 向HTML提交按钮添加链接

Php 向HTML提交按钮添加链接,php,html,Php,Html,我刚刚进入mysql,我正在创建一个基本的注册页面。但是,当我单击submit时,我希望被引导到另一个页面,比如说您登录的页面,就像许多站点一样 如何允许submit按钮链接到新页面。我知道这会很简单,但我已经看过了,似乎找不到太多 这是我尝试过的当前代码: <html> <head> <title>MySQL Test - Registration</title> <script LANGUAGE="JavaScript"

我刚刚进入mysql,我正在创建一个基本的注册页面。但是,当我单击submit时,我希望被引导到另一个页面,比如说您登录的页面,就像许多站点一样

如何允许submit按钮链接到新页面。我知道这会很简单,但我已经看过了,似乎找不到太多

这是我尝试过的当前代码:

<html>

<head>
    <title>MySQL Test - Registration</title>
    <script LANGUAGE="JavaScript">
        function testResults() {
        window.document.location.href = "http://www.google.com";
        }
    </script>
</head>

<body>
    <form action = "rego.php" method = "POST">
        Username:<br/>
        <input type = "text" name = "username"/><br/>
        Password:<br/>
        <input type = "password" name = "password"/><br/>
        Confirm Password:<br/>
        <input type = "password" name = "passvery"/><br/>
        Email:<br/>
        <input type = "text" name = "email"/><br/><br/>

        Please select your gender:<br/>
        <input type = "radio" name = "gender" value = "male"/>Male &nbsp&nbsp&nbsp&nbsp&nbsp
        <input type = "radio" name = "gender" value = "female"/>Female<br/><br/>

        <input type = "checkbox" name = "agree" value = "agree"/>I agree to the terms and conditions.<br/>
        <br/>
        <input type = "submit" value = "Sign Up!" onclick = "javascript:testresults()" />

    </form>
</body>
</html>

Form action=rego.php意味着您的表单将提交到该文件

如果要在rego.php之后转到其他地方,则应在任何输出之前从该文件重定向,例如使用location头:

// do stuff (registration)

header("Location: another-php.php");

Form action=rego.php意味着您的表单将提交到该文件

如果要在rego.php之后转到其他地方,则应在任何输出之前从该文件重定向,例如使用location头:

// do stuff (registration)

header("Location: another-php.php");

为什么不直接从rego.php脚本重定向呢?您希望在rego.php中进行一些处理,即向数据库添加记录或通知用户他们已经使用该电子邮件地址注册。因此,在插入新记录后,将用户重定向到登录页面。您可以在PHP脚本中添加头调用来执行重定向。此外,您的函数还需要在提交句柄中进行CAMELCASE处理。为什么不直接从rego.php脚本重定向?您希望在rego.php中进行一些处理,即向数据库添加记录或通知用户他们已使用该电子邮件地址注册。因此,在插入新记录后,将用户重定向到登录页面。您可以在PHP脚本中添加头调用来执行重定向。另外,你的函数需要在你的提交手册中加上camelcase。我完全忘记了这一点:我已经有很长一段时间没有用PHP/HTML编写了,基本上只是重新开始。谢谢你!我发现了一个问题,那就是如果我想回到注册页面,我不能,它只是将我重定向到首页。有办法吗?你说的回去是什么意思?如果出现错误,是否重新显示注册表?为此,您可以使用条件。如果RegistrationSuccess{redirect}或者{再次显示表单}啊,我已经完全忘记了这一点:我已经有一段时间没有用PHP/HTML编写了,基本上只是重新开始。谢谢你!我发现了一个问题,那就是如果我想回到注册页面,我不能,它只是将我重定向到首页。有办法吗?你说的回去是什么意思?如果出现错误,是否重新显示注册表?为此,您可以使用条件。ifregistrationSuccess{redirect}else{再次显示表单}