karatekid36 Posted May 14, 2007 Share Posted May 14, 2007 When I enter the information I need to in the form and then submit it, it should redirect the user to another page, but in the case of the current code, it is producing a header error instead.... <?php // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for a starting semester. if (empty($_POST['start_semester'])) { $errors[] = 'You forgot to enter a starting semester.'; } else { $ss = escape_data($_POST['start_semester']); } // Check for an starting year. if (empty($_POST['start_year'])) { $errors[] = 'You forgot to enter a starting year.'; } else { $sy = escape_data($_POST['start_year']); } // Check for a ending semester. if (empty($_POST['end_semester'])) { $errors[] = 'You forgot to enter an ending semester.'; } else { $es = escape_data($_POST['end_semester']); } // Check for an ending year. if (empty($_POST['end_year'])) { $errors[] = 'You forgot to enter an ending year.'; } else { $ey = escape_data($_POST['end_year']); } // Check for a master. if (empty($_POST['master'])) { $errors[] = 'You forgot to enter a master.'; } else { $ma = escape_data($_POST['master']); } // Check for a lt. if (empty($_POST['lieutenant'])) { $errors[] = 'You forgot to enter a lieutenant master.'; } else { $lt = escape_data($_POST['lieutenant']); } // Check for a exc. if (empty($_POST['exchequer'])) { $errors[] = 'You forgot to enter a exchequer.'; } else { $ex = escape_data($_POST['exchequer']); } // Check for a brother. if (empty($_POST['bal'])) { $errors[] = 'You forgot to enter a brother at large.'; } else { $bl = escape_data($_POST['bal']); } // Check for a scribe. if (empty($_POST['scribe'])) { $errors[] = 'You forgot to enter a scribe.'; } else { $sc = escape_data($_POST['scribe']); } // Check for a Rush chair. if (empty($_POST['rush'])) { $errors[] = 'You forgot to enter a rush chair.'; } else { $rc = escape_data($_POST['rush']); } // Check for a IFC chair. if (empty($_POST['ifc'])) { $errors[] = 'You forgot to enter an IFC chair.'; } else { $ifc = escape_data($_POST['ifc']); } // Check for a Risk Manager. if (empty($_POST['risk'])) { $errors[] = 'You forgot to enter Risk Manager.'; } else { $rm = escape_data($_POST['risk']); } // Check for a House Manager. if (empty($_POST['house'])) { $errors[] = 'You forgot to enter House Manager.'; } else { $hm = escape_data($_POST['house']); } // Check for a Pledge Manager. if (empty($_POST['pledge'])) { $errors[] = 'You forgot to enter Pledge Master.'; } else { $pm = escape_data($_POST['pledge']); } // Check for a Sentinel. if (empty($_POST['sentinel'])) { $errors[] = 'You forgot to enter Pledge Master.'; } else { $sn = escape_data($_POST['sentinel']); } if (empty($errors)) { // If everything's OK. // Register the user in the database. // Check for previous registration. $query = "SELECT eb_id FROM eboard WHERE (start_semester='$ss' AND (start_year='$sy')"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. $query = "INSERT INTO eboard (start_semester, start_year, end_year, end_semester, master, lt, scribe, bal, exchec, rush, pledge, risk, ifc, house, sentinel) VALUES ('$ss', '$sy', '$ey', '$es', '$ma', '$lt', '$sc', '$bl', '$ex', '$rc', '$pm', '$rm', '$ifc', '$hm', '$sn')"; $result = @mysql_query ($query); // generate useful error message // Run the query. if ($result) { // If it ran OK. // Send an email, if desired. // Redirect the user to the thanks.php page. // Start defining the URL. $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 .= 'view_eboards.php'; header("Location: $url"); exit(); } else { // If it did not run OK. $errors[] = 'You could not add the E-Board due to a system error. We apologize for any inconvenience.'; // Public message. $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message. } } else { // Email address is already taken. $errors[] = 'The E-Board has already been entered.'; } } // End of if (empty($errors)) IF. // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional. // Begin the page now. $page_title = 'Enter a New E-Board'; include ('./includes/header.html'); if (!empty($errors)) { // Print any error messages. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // Create the form. ?> <h2>Add an Executive Board</h2> <form action="enter_eboard_2.php" method="post"> <p>Starting Semester: <label> <input type="radio" name="start_semester" value="Fall" /> Fall</label> <label> <input type="radio" name="start_semester" value="Spring" /> Spring</label> <?php // Make the years pull-down menu. echo '<select name="start_year">'; $year = 2005; while ($year <= 2020) { echo "<option value=\"$year\">$year</option>\n"; $year++; } echo '</select>'; ?> </p> <p>Ending Semester: <label> <input type="radio" name="end_semester" value="Fall" /> Fall</label> <label> <input type="radio" name="end_semester" value="Spring" /> Spring</label> <?php // Make the years pull-down menu. echo '<select name="end_year">'; $year = 2005; while ($year <= 2020) { echo "<option value=\"$year\">$year</option>\n"; $year++; } echo '</select>'; ?> </p> <p><b>Master</b> <select name="master"><option value>No Brother</option> <?php require_once ('mysql_connect.php'); $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Lieutenant Master</b> <select name="lieutenant" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Exchequer</b> <select name="exchequer" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Brother-At-Large</b> <select name="bal" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Scribe</b> <select name="scribe" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Sentinel</b> <select name="sentinel" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Rush Chair</b> <select name="rush" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Pledge Master</b> <select name="pledge" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>IFC Representative</b> <select name="ifc" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>Risk Manager</b> <select name="risk" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><b>House Manager</b> <select name="house" ><option>No Brother</option> <?php $query = "SELECT user_id, CONCAT_WS(' ', first_name, last_name) AS name FROM brothers ORDER BY last_name, first_name ASC"; echo $query.'<br><br>'; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> </select></p> <p><input type="submit" name="submit" value="Enter E-Board" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/ Share on other sites More sharing options...
btherl Posted May 14, 2007 Share Posted May 14, 2007 Have you read http://www.phpfreaks.com/forums/index.php/topic,37442.0.html ? Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/#findComment-252509 Share on other sites More sharing options...
karatekid36 Posted May 14, 2007 Author Share Posted May 14, 2007 I read it twice and yet was unsure why my code was causing this error. Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/#findComment-252510 Share on other sites More sharing options...
btherl Posted May 14, 2007 Share Posted May 14, 2007 Try commenting out your header() call (so it simply exits without trying to redirect) and take a look at the source of your page from the browser. There's probably something displayed there. That's what you need to get rid of. It may be blank spaces being displayed.. if so, you need to get rid of THEM too Use the "View" menu in the browser to access the source. Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/#findComment-252515 Share on other sites More sharing options...
karatekid36 Posted May 14, 2007 Author Share Posted May 14, 2007 this is the top portion of the view source.. I do not see a problem...Is there? <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Enter a New E-Board</title> <style type="text/css" media="all">@import "./includes/layout.css";</style> </head> <body> <div id="wrapper"><!-- Goes with the CSS layout. --> <div id="content"><!-- Goes with the CSS layout. --> <div id="nav"><!-- Links section --> <ul> <li class="navtop"><a href="index.php" title="Go to the Home Page">Home</a></li> <li><a href="register.php" title="Register">Add a Brother</a></li> <li><a href="view_eboards.php" title="E-Boards">E-Boards</a></li> <li><a href="view_users.php" title="View the Existing Users">View Brothers</a></li> <li><a href="password.php" title="Change Your Password">Change Password</a></li> <li><a href="logout.php" title="Log Out">Log Out</a></li> </ul> </div> <!-- Script 7.1 - header.html --> <!-- Start of page-specific content. --><h2>Add an Executive Board</h2> <form action="enter_eboard.php" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/#findComment-252527 Share on other sites More sharing options...
btherl Posted May 14, 2007 Share Posted May 14, 2007 There is a BIG problem there. In order for headers to work, you must see nothing when you do "view source". Did you follow these steps? 1. Comment out the header() call, but leave exit() there 2. Submit the form with data that should trigger the redirect 3. Use "view source" At step 3, you should see an empty page. If you don't, then alter your script so you DO see an empty page. If you see an empty page but still have the header error, then you probably have some "invisible" output, like a space or a newline. Is there anything before your starting "<?php" tag? By anything I mean anything, even a single space or a blank line. Quote Link to comment https://forums.phpfreaks.com/topic/51259-why-is-this-code-producing-a-header-output-error/#findComment-252559 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.