karatekid36 Posted May 13, 2007 Share Posted May 13, 2007 When I "submit" this form it does not send any data to the table like it should and also when it submits and is successful, it should redirect to a different page I have built. It is doing neother of these things. When I hit the submit button, it simply reloads the page. What is this error? <?php if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); $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 eboard 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', '$es', '$ey', '$ma', '$lt', '$sc', '$bl', '$ex', '$rc', '$pm', '$rm', '$ifc', '$hm', '$sn')"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK. // 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.'; // Public message. $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message. } } else { // E-Board is already Entered. $errors[] = 'The E-Board address has already been registered.'; } // End of if (empty($errors)) IF. // Close the database connection. // Dont Close It Yet! }} else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional. // Begin The Page $page_title = 'Enter a New E-Board'; include ('includes/header.html'); ?> <h2>Add an Executive Board </h2> <form action="enter_eboard.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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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="rc" ><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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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="rm" ><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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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="hm" ><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"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$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="Add 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/51136-solved-when-i-submit-my-form/ Share on other sites More sharing options...
suttercain Posted May 13, 2007 Share Posted May 13, 2007 You are trying to process the page to enter_eboard.php <form action="enter_eboard.php" method="post"> What is the name of the page with the form in it? Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251740 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 First, if the form and processing are on the same page, you can set the action="<?=$_SERVER['PHP_SELF'] ?> Second, put this at the top of the page to ensure that the post vars are being sent <?php echo '<pre>'; print_r($_POST); echo '</pre>'; ?> If you get nothing, then the form is not being submitted correctly. If you get an array print out, then the form is being sent and you should start going line by line and echo'ing out some stuff to see where the script is breaking at Nate Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251743 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 the name of the page is enter_eboard.php and I am 99% sure that it is not sending anything to the database because when I look at it in myphpAdmin, there is nothing in the table. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251744 Share on other sites More sharing options...
AndyB Posted May 13, 2007 Share Posted May 13, 2007 I am 99% sure that it is not sending anything to the database because when I look at it in myphpAdmin, there is nothing in the table. So why not make that 100%? Have the form processing script echo out the exact query that's sent to the database. Copy/paste that as an SQL query in phpMyAdmin and see if it puts stuff into the database. If it doesn't, chances are that the query string itself will tell you what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251747 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 Well, the first step is to see if the form is even posting anything to the page your expecting it to post to. So.... at the top of enter_eboard.php add <?php echo '<pre>'; print_r($_POST); echo '</pre>'; ?> This is step 1. Adding into the database is somewhere around step 7-10. 2-?? is the processing pieces and all that happens between submission and inserting. If this gives you results, then we can move on to step 2 Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251749 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I have placed that code at the top of the file. Now which information would you like from the code? I am getting an array(), but that is it. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251754 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 Did you then submit the form after you placed that code at the top of the page?? Here is what I receive from a simple form I have. I filled it in with test in all fields and submitted the page. If your not getting something that looks like this Array ( [fname] => test [lname] => test => test [username] => test [level] => 2 [submit] => Submit ) then your form is not even submitting the data as it should be. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251765 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I get this at the top... Array ( [start_semester] => Fall [start_year] => 2005 [end_semester] => Spring [end_year] => 2005 [master] => 42 [lieutenant] => 2 [exchequer] => 27 [bal] => 5 [scribe] => 29 [sentinel] => 18 [rc] => 22 [ifc] => 30 [rm] => 9 [hm] => 4 [submit] => Add E-Board [submitted] => TRUE ) Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251768 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 That proves that the page is sending the data as it should be. remove that added code and do what AndyB suggested. place echo $query; right below your query and see what it says. If it *looks* right, copy and paste that echo'd query into phpmyadmin.... chances are you will get an error message there Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251774 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I am not sure how you want me to use the echo. When I copy and paste the query into phpadmin, it works just fine. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251778 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 simply place this below each one of your queries echo $query.'<br>'; As you do this, you can look at those queries and verify if they hold the data you are expecting. If you can take your insert query and copy what it echo's onscreen and paste it into PhpMyAdmin and have it insert the data correctly, then the script should be inserting the data properly as well. Are you getting any errors when this script runs? Do you have a URL so I can see it myself? Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251780 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I sent the URL to you via private message when I added the echo statement, nothing happened when I clicked the submit button. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251783 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 got it.... do me a favor and go through your code and add echo $query.'<br><br>'; below each of the queries in your page. Post back when you have done that and I will then submit the page and look at the results displayed. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251790 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I put that below every query. Let me know. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251792 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 hmmmmmmm... on enter_eboard.php When I submit the page, I should be seeing all your queries. But I am not. Time for line by line troubleshooting. The goal now is to verify that each part of the script is doing what it is supposed to do. one by one, in your if statements echo something like I have below. If you can read it, then you know that part is processing. The goal is to find the piece that is not processing the way it should. Take a look at the example I have here, and imitate that piece by piece on your script. <?php if (isset($_POST['submitted'])) { echo 'If You can read this, go to the next if statement and echo something there, form submitted properly.'; require_once ('mysql_connect.php'); $errors = array(); // Initialize error array. ......... ?> Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-251797 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Author Share Posted May 13, 2007 I figured it out. Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/51136-solved-when-i-submit-my-form/#findComment-252381 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.