tombob10 Posted June 5, 2012 Share Posted June 5, 2012 Apologies its so long but the following code wont insert into DB, I cant see why. The errors work but if I fill everything in it still gives the last error message that their has been a problem. Is their any error reporting I can do to see why its not entering the DB? <?php if(isset($_POST['form_id'])){ $category = mysql_real_escape_string(trim($_POST['category'])); $firstname = mysql_real_escape_string(trim($_POST['firstname'])); $surname = mysql_real_escape_string(trim($_POST['surname'])); $email = mysql_real_escape_string(trim($_POST['email'])); $website = mysql_real_escape_string(trim($_POST['website'])); $company = mysql_real_escape_string(trim($_POST['company'])); $building = mysql_real_escape_string(trim($_POST['building'])); $streetname = mysql_real_escape_string(trim($_POST['streetname'])); $state = mysql_real_escape_string(trim($_POST['state'])); $postcode = mysql_real_escape_string(trim($_POST['postcode'])); $aboutcompany = mysql_real_escape_string(trim($_POST['aboutcompany'])); $events = mysql_real_escape_string(trim($_POST['events'])); $error = false; if(!isset($category) || empty($category)) { $error = "Please select a category."; } if(!isset($firstname) || empty($firstname)) { $error = "Please enter a First Name."; } if(!isset($surname) || empty($surname)) { $error = "Please enter a Surname."; } if(!isset($email) || empty($email)) { $error = "Please enter an email."; } if(!isset($website) || empty($website)) { $error = "Please enter a Website Domain."; } if(!isset($company) || empty($company)) { $error = "Please enter a Company Name."; } if(!isset($building) || empty($building)) { $error = "Please enter a Building Name or Number."; } if(!isset($streetname) || empty($streetname)) { $error = "Please enter a Street Name."; } if(!isset($state) || empty($state)) { $error = "Please enter a State."; } if(!isset($postcode) || empty($postcode)) { $error = "Please enter a Zip Code/Post Code."; } if(!isset($aboutcompany) || empty($aboutcompany)) { $error = "Please enter details about your company."; } if(!$error) { $query = mysql_query("INSERT INTO organiserdbase (category, firstname, surname, email, website, company, building, streetname, state, postcode, aboutcompany, events) VALUES ('".$category."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$buidling."', '".$streetname."', '".$state."', '".$postcode."', '".$aboutcompany."', '".$events."')"); if($query) { } else { $error = "There was a problem with the submission. Please try again."; } } } ?> <div id="registerpagecell"> <div id="registerpageheader"> Register </div> <div id="registerform"> <form id="form_id" class="appnitro" method="post" action=""> <?php if($error) echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />"; ?> <ul > <li id="li_1" > <select class="element select medium" id="category" name="category"> <label class="description" for="element_3">Choose Category:</label> </br> <option value="" selected="selected">Please Choose a Job Role:</option> <option value="Event Manager" >Event Manager</option> <option value="Event Managent Courses" >Event Managent Courses</option> <option value="Event Management Software" >Event Management Software</option> <option value="Entertainment Staff" >Entertainment Staff</option> <option value="Furniture Hire" >Furniture Hire</option> <option value="Caterers" >Caterers</option> <option value="Private Home" >Private Home</option> <option value="Reception Room" >Reception Room</option> <option value="Hotel" >Hotel</option> <option value="Night Club" >Night Club</option> <option value="Spa/Beauty Facility" >Spa/Beauty Facility</option> <option value="Website Designer" >Website Designer</option> <option value="Event Marketers" >Event Marketers</option> <option value="Event Security" >Event Security</option> <option value="Event Booking Software" >Event Booking Software</option> <option value="Ticketing Software" >Ticketing Software</option> <option value="Transport Company" >Transport Company</option> <option value="Health & Safety Specialist" >Health & Safety Specialist</option> <option value="Sports Facility" >Sports Facility</option> <option value="Event Sponsors" >Event Sponsors</option> <option value="Music Promoter" >Music Promoter</option> <option value="Visual Effects Specialist" >Visual Effects Specialist</option> <option value="Property Maintentance" >Property Maintentance</option> </select> </li> <li id="li_1" > <label class="description" for="element_1">First Name:</label> <div> <input id="element_1" name="firstname" class="registerforminput" type="text" value="<?php if($_POST['firstname']) echo $_POST['firstname']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Surname:</label> <div> <input id="element_1" name="surname" class="registerforminput" type="text" value="<?php if($_POST['surname']) echo $_POST['surname']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Email:</label> <div> <input id="element_1" name="email" class="registerforminput" type="text" value="<?php if($_POST['email']) echo $_POST['email']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Company Website:</label> <div> www. <input id="element_1" name="website" class="registerforminput" type="text" value="<?php if($_POST['website']) echo $_POST['website']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Company Name:</label> <div> <input id="element_1" name="company" type="text" class="registerforminput" value="<?php if($_POST['company']) echo $_POST['company']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Building Name/Number:</label> <div> <input id="element_1" name="building" class="registerforminput" type="text" width="600" value="<?php if($_POST['building']) echo $_POST['building']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Street Name:</label> <div> <input id="element_1" name="streetname" class="registerforminput" type="text" maxlength="600" value="<?php if($_POST['streetname']) echo $_POST['streetname']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">State:</label> <div> <input id="element_1" name="state" class="registerforminput" type="text" maxlength="600" value="<?php if($_POST['state']) echo $_POST['state']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_1">Zip Code/Post Code:</label> <div> <input id="element_1" name="postcode" class="registerforminput" type="text" maxlength="600" value="<?php if($_POST['postcode']) echo $_POST['postcode']; ?>" /> </div> </li> <li id="li_1" > <label class="description" for="element_2">About Your Company:</label> <div> <textarea id="element_2" name="aboutcompany" class="element textarea medium" value="<?php if($_POST['aboutcompany']) echo $_POST['aboutcompany']; ?>"></textarea> </div> </li> <li id="li_1" > <label class="description" for="element_2">Your Events:</label> <div> <textarea id="element_2" name="events" class="element textarea medium" value="<?php if($_POST['events']) echo $_POST['events']; ?>"></textarea> </div> </li> <li class="buttons"> <input type="hidden" name="form_id" value="submit" /> <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /> </li> </ul> </form> </div> </div> Link to comment https://forums.phpfreaks.com/topic/263703-not-entering-db-any-error-reporting-i-can-try/ Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 Instead of displaying some custom error message when there is an error, why not have a look and see what that real error was? if (!$query) { trigger_error(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/263703-not-entering-db-any-error-reporting-i-can-try/#findComment-1351386 Share on other sites More sharing options...
litebearer Posted June 5, 2012 Share Posted June 5, 2012 Perhaps my eyes are bleary, but where are you connecting to the database? Link to comment https://forums.phpfreaks.com/topic/263703-not-entering-db-any-error-reporting-i-can-try/#findComment-1351388 Share on other sites More sharing options...
justlukeyou Posted June 5, 2012 Share Posted June 5, 2012 Sorted, I had a the connection wrong. Thats a great trick thorpe, thanks. Link to comment https://forums.phpfreaks.com/topic/263703-not-entering-db-any-error-reporting-i-can-try/#findComment-1351389 Share on other sites More sharing options...
trq Posted June 5, 2012 Share Posted June 5, 2012 Cool, so you have multiple accounts too? Just awesome! tombob10 has now been banned. Link to comment https://forums.phpfreaks.com/topic/263703-not-entering-db-any-error-reporting-i-can-try/#findComment-1351391 Share on other sites More sharing options...
Recommended Posts