Variables in Header Function

I’m having trouble getting my page to redirect. The are three things that could be wrong, I’m using the parameters wrong (redirecting to the same page, just with a different parameter), variables in the header function, or syntax error.

Here is the PHP code in “regvalid.php” (focus on the header functions).


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

$resultUser = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Username` = "$_POST[user]"");
if ($resultUser > 1)  header("Location:http://bsatroop878.org");

$resultEmail = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Email`= '$_POST[email]'");
if ($_POST['email'] >= 1) header("Location: '$root' . '$email_use'");

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

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

$resultVerify = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Vaild` = '$verify'");

while ($resultVerify >= 1){
	$verifyBase = microtime();
	$verify = md5($verifyBase);
	$resultVerify = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Vaild` = '$verify'");
}

$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);

header("Location: '$root' . '$no_error'");
?>

Here is the “redirect.php” code.


<?php
##Place all of you redirects in this file
#Change this variable to the root of you site. Ex. http://bsatroop878.org/, http://localhost/social/ 
#Make sure you end with a trailing slash
$root = "http://localhost/social/";

#File directs
$no_error = "regvalid.php?no_error=1";
$email_use = "regvalid.php?email_use=1";
$name_use = "regvalid.php?name_exists=1";
?>

Here is the HTML of “regvaild.php”.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Social Quests - Uh-oh!</title>
<link rel="stylesheet" type="text/css" href="css/docs.css" />
<link rel="shortcut icon" href="images/favicon.ico"/>
</head>
<body class="twoColLiqLtHdr">
<?php
if (isset($_GET['name_exists'])) {
  require("includes/registration/username.php");
} 
if (isset($_GET['email_use'])) {
  require("includes/registration/email.php");
} 
if (isset($_GET['no_error'])) {
  require("includes/registration/no_error.php");
} 
?>
</body>
</html>

I may have put to much information, but if you need more, just say so.

Thanks for the help!:slight_smile:

header(“Location: ‘$root’ . ‘$email_use’”);

header('Location: '.$root.$email_use);

I wasn’t able to try your code becasue there is an error before the header function and I don’t know what it is.

Here is the code.


$resultUser = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Username` = "$_POST[user]);
if ($resultUser > 1)  header("Location: http://bsatroop878.org");

Required files before it reads the the above code.


<?php
$host="localhost";
$username="root";
$password="temple01";
$db_name="socialquests";

$con = mysql_connect("$host", "$username", "temple01"); 
if(!$con)
	{
		die('Could not connect:' . mysql_error());
	}
	
mysql_select_db("$db_name", $con) or die('Could not connect' . mysql_error());
?>


<?php
$root = "http://localhost/social/";

$no_error = "regvalid.php?no_error=1";
$email_use = "regvalid.php?email_use=1";
$name_use = "regvalid.php?name_exists=1";
?>

$resultUser = mysql_query("SELECT COUNT(*) FROM sq_users WHERE Username = "$_POST[user]);

error 1: You are missing the concatenation operator . before $_POST
error 2: You need to use quotes ’ around the Username value in the query: Username = ‘name’
error 3: You need to mysql_real_escape_string() any string variables that you use in a query, or you will get: Username = ‘O’Reilly’ which is obviously not correct sql

Both of your posts had problems with basic strings, you can read more about them here.

Thanks for the help! I got it! :rofl: