connex Posted April 18, 2009 Share Posted April 18, 2009 Okay, this code was working fine before, but for some reason when I try clicking submit, the form wont even process! Any idea what can be wrong? <?php require_once("includes/session.php"); // check if user is logged in require_once("includes/connection.php"); // page requires database connection, so grab database values require_once("includes/functions.php"); // get all functions include_once("includes/form_functions.php"); // get all form functions // Get server date $date = date('Y-m-d H:i:s'); // If the submit button has been processed, process all following code. if (isset($_POST['submit'])) { // Form has been submitted. $errors = array(); // Builds an array to hold any errors generated. // perform validations on the form data $required_fields = array('vipno', 'custname', 'quantity', 'type', 'colour', 'ordercompleted'); // if required fields not completed, all field names to the error array $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); // make sure submitted data works well with MySQL $vipno = trim(mysql_prep($_POST['vipno'])); $custname = trim(mysql_prep($_POST['custname'])); $quantity = trim(mysql_prep($_POST['quantity'])); $type = trim(mysql_prep($_POST['type'])); $quality = $_POST['colour']; $mailrmfirst = trim(mysql_prep($_POST['mailrmfirst'])); $mailrmsecond = trim(mysql_prep($_POST['mailrmsecond'])); $mailrmstan = trim(mysql_prep($_POST['mailrmstan'])); $mailair = trim(mysql_prep($_POST['mailair'])); $ordercompleted = $_POST['ordercompleted']; $userid = $_SESSION['username']; // if they are no errors in the data, do the following piece of code if ( empty($errors) ) { // upload the file // check if file is of a certain type if ((($_FILES["jobfile"]["type"] == "image/gif") || ($_FILES["jobfile"]["type"] == "image/jpeg") || ($_FILES["jobfile"]["type"] == "image/pjpeg")) // check if the size is not too big && ($_FILES["jobfile"]["size"] < 2000000)) { // if they are any errors if ($_FILES["jobfile"]["error"] > 0) { //store error in message variable so it can be displayed later $ferrors .= "Error: " . $_FILES["jobfile"]["error"] . "<br />"; } // if they are no errors else { // check if a file with the same name already exists if (file_exists("uploaded/" . $_FILES["jobfile"]["name"])) { // store error in message variable so it can be displayed later $ferrors .= $_FILES["jobfile"]["name"] . " already exists. "; } else // if they are no errors, move temp uploaded file to folder { move_uploaded_file($_FILES["jobfile"]["tmp_name"], "uploaded/" . $_FILES["jobfile"]["name"]); } } } else // if file is not invalid { $ferrrors .= "Invalid file"; } $errors = array_merge($errors, $ferrors); // store file name in a variable $jobfile = $_FILES["jobfile"]["name"]; // generate SQL query to insert all data into the database $query = "INSERT INTO jobs (datestarted, vipno, custname, jobfile, quantity, type, colour, mailrmfirst, mailrmsecond, mailrmstan, mailair, ordercompleted, userid) VALUES ('{$date}', '{$vipno}', '{$custname}', '{$jobfile}', '{$quantity}', '{$type}', '{$colour}', '{$mailrmfirst}', '{$mailrmsecond}', '{$mailrmstan}', '{$mailair}', '{$ordercompleted}', '{$userid}')"; // process the query $result = mysql_query($query, $connection); // if the query was a success, display message if ($result) { $message .= "The job was successfully created."; // if the query did not work for any reason, display error message } else { $message .= "The job could not be created."; $message .= "<br />" . mysql_error(); } } else { // if they were any errors in the form display a a message if (count($errors) == 1) { $message .= "There was 1 error in the form."; // if they were more then 1 error, display the total amount } else { $message .= "There were " . count($errors) . " errors in the form."; } } } else { // If form has not been submitted, set default blank values. $vipno = ""; $custname = ""; $jobfile = ""; $quantity = ""; $colour = "0"; $mailrmfirst = ""; $mailrmsecond = ""; $mailrmstan = ""; $mailair = ""; $ordercompleted = "0"; } // start to output the page headers include("includes/header.php"); // break out of PHP to output HTML ?> <table class="main" width="850"> <tr> <td width="25%"> <a href="staff.php">Return to Menu</a><br /> </td> <td width="75%> <h2>Create New Job</h2> <?php // if no errors occoured, output all the messages, and details of the uploaded file if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>"; echo "Stored in: " . "uploaded/" . $_FILES["jobfile"]["name"] . "<br />"; echo "Type: " . $_FILES["jobfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["jobfile"]["size"] / 1024) . " Kb<br />"; } // if errors exist, output all errors if (!empty($errors)) { display_errors($errors); } ?> <form action="new_job.php" method="post" enctype="multipart/form-data"> <table> <tr> <td colspan="2"><h3>Job Details</h3></td> </tr> <tr> <td>VIPNo:</td> <td><input type="text" name="vipno" maxlength="10" value="" /></td> </tr> <tr> <td>Customer Name:</td> <td><input type="text" name="custname" maxlength="30" value="" /></td> </tr> <tr> <td>Job File:</td> <td><input type="file" name="jobfile" id="jobfile" size="20"></td> </tr> <tr> <td>Quantity:</td> <td><input type="text" name="quantity" maxlength="10" value="" /></td> </tr> <tr> <td>Type:</td> <td> <select name="type"> <option value="1">Letter</option> <option value="2">Cheque</option> <option value="3">Booklet</option> </select> </td> </tr> <tr> <td>Colour:</td> <td> <input type="radio" name="colour" value="0" /> Black & White <input type="radio" name="colour" value="1" /> Colour </td> <tr> <td colspan="2"><h3>Mailing</h3></td> </tr> <tr> <td>Royal Mail First Class:</td> <td><input type="text" name="mailrmfirst" maxlength="10" value="" /></td> </tr> <tr> <td>Royal Mail Second Class:</td> <td><input type="text" name="mailrmsecond" maxlength="10" value="" /></td> </tr> <tr> <td>Royal Mail Overseas:</td> <td><input type="text" name="mailrmstan" maxlength="10" value="" /></td> </tr> <tr> <td>Special Delivery:</td> <td><input type="text" name="mailair" maxlength="10" value="" /></td> </tr> <tr> <td colspan="2"><h3>Status</h3></td> </tr> <tr> <td>Order Completed:</td> <td><input type="checkbox" name="ordercompleted" value="1" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Create Job"></td> </tr> </table> </form> </td> </tr> </table> <?php include("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/ Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Before what? What did you change? if you add a die('x'); to just after if (isset($_POST['submit'])) { you'll see if it's getting that far. If it's not then likely something is broken client side. Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813176 Share on other sites More sharing options...
PFMaBiSmAd Posted April 18, 2009 Share Posted April 18, 2009 this code was working fine beforeBefore what? Without telling us what exactly before was and how that relates to now, that is a pointless statement. the form wont even process!Yes but what is it doing? What do you see in front of you? A blank page? The form again? Php error messages? Messages from your form processing code? When you expect someone else to help you, you must communicate sufficient information for them to have a chance of helping you. Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813177 Share on other sites More sharing options...
connex Posted April 19, 2009 Author Share Posted April 19, 2009 Sorry about that, It was working before I changed some tables (putting each form in each row), but since it stopped working, I tried undoing what I did but there's still the same problem. What the script is supposed to do is add a job, with those fields into a database. Here is my script online so you can see it in action (I'm still new so its not that impressive yet): http://theadvoor.com/work/capita/login.php Username: Client Password: pass If you go to 'Add Job' upon login, you will see that for some reason, whenever I click the 'Create Job' button, the page does not even reload or anything. It's the same thing as having a button on a page which no actions to it - you can click it as many times as you want but nothing will happen... @soak , added the code you gave me but still after adding it, it doesn't even lift off the page let alone manage to process that part... Any ideas? Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813723 Share on other sites More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 Re-type this line manually: <form action="new_job.php" method="post" enctype="multipart/form-data"> The validator (http://validator.w3.org/check) looks to be reporting some invalid characters. Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813737 Share on other sites More sharing options...
mrMarcus Posted April 19, 2009 Share Posted April 19, 2009 you missing a closing " here : <td width="75%>, just before your <form>. Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813770 Share on other sites More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 Ahhh, well spotted. That'll be it. Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813776 Share on other sites More sharing options...
connex Posted April 19, 2009 Author Share Posted April 19, 2009 Ah didn't see that one! Thanks a lot! Working perfectly fine now Link to comment https://forums.phpfreaks.com/topic/154641-solved-php-and-forms/#findComment-813817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.