Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Form with 2 Submit Buttons, Conditional Works, but no Header Redirect
    text
    copied!<p>I have a log-in form on a webpage and I want users to be able to log-in or register. At the top of the page I have the PHP script with the conditional testing for which submit button was pressed. The Log-in portion works fine. The "Register" portion works (meaning, it gets into the if-statement), but it doesn't redirect to my register.php site. Any thoughts?</p> <p>I've tried changing the order of the if/elseif statements but to no avail. I get no warnings from this script, but it just reloads the page rather than redirecting to register.php.</p> <p>To see the actual webpage, go <a href="http://www.mynextbit.com/Pages/newtemplateTEST.php" rel="nofollow">here</a>.</p> <pre><code>&lt;?php $error = ''; session_start(); ob_start(); if (isset($_POST['register'])) { header("http://www.mynextbit.com/authenticate/register.php"); } elseif (isset($_POST['login'])) { session_start(); $username = trim($_POST['username']); $_SESSION['user'] = $username; $password = trim($_POST['pwd']); // location to redirect on success $redirect = 'http://www.mynextbit.com/Pages/newtemplateTEST.php'; require_once('../includes/authenticate_mysqli.inc.php'); } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ... </code></pre> <p>And, the HTML FORM...</p> <pre><code>&lt;?php if ($error) { echo "&lt;p&gt;$error&lt;/p&gt;"; } if (!$_SESSION['user']) { ?&gt; &lt;font color="red"&gt;&lt;i&gt;&lt;userlogin&gt;Please Log In&lt;/userlogin&gt;&lt;/i&gt;&lt;/font&gt;&lt;br /&gt; &lt;form id="form1" method="post" action="" style="margin-left: 15px"&gt; &lt;label for="username" &gt;&lt;font size="-1"&gt;Username:&lt;/font&gt;&lt;/label&gt; &lt;input type="text" name="username" id="username"&gt; &lt;br /&gt; &lt;label for="pwd"&gt;&lt;font size="-1"&gt;Password:&lt;/font&gt;&lt;/label&gt; &lt;input type="password" name="pwd" id="pwd"&gt; &lt;br /&gt; &lt;input name="login" type="submit" id="login" value="Log in" style="display:inline"&gt; or &lt;input name="register" type="submit" id="register" value="Register" style="display:inline"&gt; &lt;/form&gt; &lt;?php } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload