Jump to content

please help me with the error message for my php registration form


littlepeg
 Share

Recommended Posts

Hi, everybody. I am a new learner for php & MySQL. I try to develop a registration form, but it could not work. The error message is as follows: "Cannot modify header information - headers already sent by (output started at C:\wamp\www\snyp\snypdb.php:20) in C:\wamp\www\snyp\bookdsfds.php on line 66" Could you please help me to sort out this problem. Any help would be grately and appreciated. :) The code as follows:<?php # Script 8.7 - bookdsfds.php// Send NOTHING to the Web browser prior to the header() line!// Check if the form has been submitted.if (isset($_POST['submitted'])) { require_once ('snypdb.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for a first name. if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn =$_POST['first_name']; } // Check for a last name. if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = $_POST['last_name']; } // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = $_POST['email']; } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = $_POST['password1']; } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everything's OK. // Register the user in the database. // Check for previous registration. $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/funder.php'; header("Location: $url"); exit(); } else { // If it did not run OK. $errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; // Public message. $errors[] = mysql_error() . 'Query: ' . $query; // Debugging message. } } else { // Email address is already taken. $errors[] = 'The email address has already been registered.'; } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL;} // End of the main Submit conditional.if (!empty($errors)) { // Print any error messages. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:'; foreach ($errors as $msg) { // Print each error. echo " - $msg\n"; } echo '</p><p>Please try again.</p>';}// Create the form.?><h2>Register</h2><form action="bookdsfds.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /></form>this is the php file the error message mentioned:// codes for snypdb.php<?php$strLocation="Home";//$strLocation="University";if($strLocation=="Home"){ $dbLocalhost=mysql_connect("localhost","root","")or die("could not connect:" .mysql_error());}else{ $dbLocalhost=mysql_connect("osiris.sunderland.ac.uk","bc2tzh","bc2tzh") or die("could not connect:" .mysql_error());}mysql_select_db("snyp", $dbLocalhost) or die("could not find detabase:" .mysql_error()); ?>

Link to comment
Share on other sites

That's not the file where the problem is. The error message says it all:Cannot modify header information - headers already sent by (output started at C:\wamp\www\snyp\snypdb.php:20) in C:\wamp\www\snyp\bookdsfds.php on line 66The reference to line 66 in bookdsfds is the line that is causing the error, the header line, but that line is not the problem. As you can see the note on the first line of the script (// Send NOTHING to the Web browser prior to the header() line!), you aren't allowed to send headers once output has been sent to the browser. The error message is indicating that the output that was sent on line 20 of the snypbd.php file is what is causing the header to fail.

Link to comment
Share on other sites

That's not the file where the problem is. The error message says it all:Cannot modify header information - headers already sent by (output started at C:\wamp\www\snyp\snypdb.php:20) in C:\wamp\www\snyp\bookdsfds.php on line 66The reference to line 66 in bookdsfds is the line that is causing the error, the header line, but that line is not the problem. As you can see the note on the first line of the script (// Send NOTHING to the Web browser prior to the header() line!), you aren't allowed to send headers once output has been sent to the browser. The error message is indicating that the output that was sent on line 20 of the snypbd.php file is what is causing the header to fail.
Thank you for your help. But would you please tell me how can I sort out this problem? :)
Link to comment
Share on other sites

If the snypdb.php looks the same as the code you submitted (use

last[/u] thing in that file, then it should work..
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...