ultratek Posted November 24, 2008 Share Posted November 24, 2008 cleaned up the code....i cannot figure out why lines 61 through 72 do not work for me to redirect to my thanks page...in the same directory....i get a blank page after i submit the register.php: <?php if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); $errors = array(); if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = escape_data($_POST['first_name']); } if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = escape_data($_POST['last_name']); } if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )"; $result = @mysql_query ($query); if ($result) { $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0 ,-1); } $url .= 'thanks.php'; header("location: $url"); exit(); } else { $errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; $errors[] = mysql_error() . '<br /><br />Query: ' . $query; } } else { $errors[] = 'The email address has already been registered.'; } } mysql_close(); } else { $errors = NULL; } $page_title = 'Register'; include ('./includes/header.html'); if (!empty($errors)) { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } ?> <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.html'); ?> section: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0 ,-1); } $url .= 'thanks.php'; header("location: $url"); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/ Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 Put ob_start(); on the first line Then ob_clean(); before you set a header. If you try to set a header after you have echoed something it won't let you. See headers_sent in PHP manual for reference. Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-697755 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Or better yet, fix your code. It makes no sense to have output to the browser if you will just use a HEADER anyways. Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-697759 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 That too Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-697770 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Blank pages are indicators that you have errors in your code (or there is just nothiing to display). Make sure you have error reporting on and that you are displaying them. Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-697778 Share on other sites More sharing options...
ultratek Posted November 24, 2008 Author Share Posted November 24, 2008 there are no echo statements before the header() and i moved the $page_title and include() to after the header() as the lesson instructed... Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-697980 Share on other sites More sharing options...
ultratek Posted November 25, 2008 Author Share Posted November 25, 2008 thank you guys for your help.. i still cant figure out why i am getting a blankpage when i submitt the register.php the script is written just like the book's... i am testing on my server...http://www.justinvenablephoto.com/practice/register.php Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698782 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Show the code where you turned this on. Blank pages are indicators that you have errors in your code (or there is just nothiing to display). Make sure you have error reporting on and that you are displaying them. Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698798 Share on other sites More sharing options...
ultratek Posted November 25, 2008 Author Share Posted November 25, 2008 <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); $errors = array(); if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = escape_data($_POST['first_name']); } if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = escape_data($_POST['last_name']); } if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )"; $result = @mysql_query ($query); if ($result) { $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0 ,-1); } $url .= '/thanks.php'; header("location: $url"); exit(); } else { $errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; $errors[] = mysql_error() . '<br /><br />Query: ' . $query; } } else { $errors[] = 'The email address has already been registered.'; } } mysql_close(); } else { $errors = NULL; } $page_title = 'Register'; include ('./includes/header.html'); if (!empty($errors)) { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } ?> <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.html'); ?> error: Warning: Cannot modify header information - headers already sent by (output started at \\boswinfs02\home\users\web\b1623\ez.ultratek\practice\mysql_connect.php:28) in \\boswinfs02\home\users\web\b1623\ez.ultratek\practice\register.php on line 71 Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698806 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Tells you the exact problem. Output on line 28 of mysql_connect.php is causing a problem with your HEADER line on 71. Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698807 Share on other sites More sharing options...
ultratek Posted November 25, 2008 Author Share Posted November 25, 2008 didnt thinkabout the require file having trouble... sure enough...whitespace.. thanks for all the help guys Quote Link to comment https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.