Jump to content

Set page up if something happens.


BMorganVA

Recommended Posts

I making a registration form.  Everything works except one part.  Depending on what the condition is (i.e. User name in use, email in use, successful registration), I want the page to show up differently.  I don't know how to do that.  I tried using the header function to different pages, but that won't work because it isn't the first thing on the page.  Here is my code:

<?php
require("includes/connect.php");

$resultUser = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Username`= "$_POST[user]"");
if ($resultUser == 1) header("Location: "Location:http://localhost/social/uregister.php"");
echo("$resultUser");

$resultEmail = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Email`= "$_POST[email]"");
if ($_POST['email'] == $resultEmail) header("Location:http://localhost/social/eregister.php");

$passwd = $_POST[password1];
$passenc = md5($passwd);

$verifyBase = microtime();
$verify = md5($verifyBase);

$sql = "INSERT INTO `sq_users` (`Username`, `Passwd`, `Email`, `Valid`)
VALUES 
('$_POST[user]', '$passenc', '$_POST[email]', '$verify')";

if(!mysql_query($sql,$con))
{
	die('Error:' . mysql_error());
}


mysql_close($con);
?>

 

Thanks for the help.  Also, if you need an example of what I'm talking about,  go to Facebook and type the wrong password when you login.  Notice the URL and how it has the parameter "?login_attempt=1".  Delete the parameter and the page displays differently.  That's what I'm trying to do.

Link to comment
https://forums.phpfreaks.com/topic/193851-set-page-up-if-something-happens/
Share on other sites

In the first part you have- Location twice (see below).  I believe that it is not parsing that and moving onto the echo statement which is outputting to the browser which will result in the output to header error.

header("Location: "Location:http://localhost/social/uregister.php"");

Additionally- if that is where you want it to go after the error is detected- then there should be an exit; directly after to prevent the script from continuing.  It should look like so--

 

header("Location: http://localhost/social/uregister.php");
exit;
echo $resultUser;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.