PHP - Forms: Input Fields Stop Working After Sending Empty Strings
On all my forms, after I send an empty string to one field, it will stop accepting values when I resubmit. My code passes through the W3C validator
Any ideas?? Similar TutorialsHi I'm currently having a problem with my form. Users submit an empty field into the database and the next time another user tries to enter it just says username has been taken. I need some help on how to confirm that the username and email field isnt empty when inserted and that the email address is in the correct format.
<?php include "base.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Management System (Tom Cameron for NetTuts)</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="main"> <?php $username = mysql_real_escape_string($_POST["username"]); $email = mysql_real_escape_string($_POST["email"]); $mxitid = mysql_real_escape_string($_SERVER["HTTP_X_MXIT_USERID_R"]); if(!isset($mxitid)) { $mxitid = "DEFAULT"; } $checkusername = mysql_query("SELECT * FROM Users WHERE mxitid = '".$mxitid."'"); $checkemail = mysql_query("SELECT * FROM Users WHERE email = '".$email."'"); if(mysql_num_rows($checkusername) == 1) { echo "<h1>Error</h1>"; echo "<p>Sorry, that username is taken. Please go <a href=\"register.php\">back</a>and try again.</p>"; } elseif(mysql_num_rows($checkemail) == 1) { echo "<h1>Error</h1>"; echo "<p>Sorry, that email is taken. Please go <a href=\"register.php\">back</a>and try again.</p>"; } elseif ($_POST["register"]) { $username = mysql_real_escape_string($_POST["username"]); if(!isset($mxitid)) $mxitid = mysql_real_escape_string($_SERVER["HTTP_X_MXIT_USERID_R"]); if(!isset($mxitid)) { $mxitid = "DEFAULT"; } $registerquery = mysql_query("INSERT INTO Users (Username,mxitid,email) VALUES('".$username."','".$mxitid."','".$email."')"); if($registerquery) { echo "<h1>Success</h1>"; echo "<p>Your account was successfully created. Please <a href=\"index9.php\">click here to start chatting</a>.</p>"; } } else { ?> <h1>Register</h1> <p>Please enter your details below to register.</p> <p>Keep it clean! or you might get banned!</p> <form method="post" action="register.php" name="registerform" id="registerform"> <fieldset> <label for="username">Username:<br> Using emoticons in your name won't work!</label><input type="text" name="username" id="username" /><br /> <label for="email">Email:<br>(We need your real one to be able to contact you!)<br> If you don't have one make use of your mxit email service.</label><input type="email" name="email" id="email" /><br /> <input type="hidden" name="mxitid" id="mxitid" value="<? $_SERVER['HTTP_X_MXIT_USERID_R']; ?>"/><br /> <input type="submit" name="register" id="register" value="Register" /> </fieldset> </form> <?php } ?> </div> </body> </html>I tried using function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { die($problem); } return $data; }but it didnt seems to work Hi guys, basically my problem is I have a jquery pop out window that holds a login form using the "require_once" function but when I enter my login details and send them, if there is another another form on the page e.g contact form it will send that form aswell so it will come up for the errors for the register form because they are empty. can anyone tell me how to stop this from happening? I have a problem w/ a widely used password protect php code. I use a business directory program that allows custom input fields. I'm using this code to password protect a business listing page in my directory code. I created custom fields for the username & password so a listing can enter their own user/pass but when I test it it won't work when I'm calling/echoing the fields. When I hardcode it w/ a user/pass it works. Any ideas on how I should recode this?: Quote <?php // Define your username and password $username = "<?php echo $custom_74; ?>"; $password = "<?php echo $custom_16; ?>"; if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } else { ?> I close the code correctly. <?php echo $custom_74; ?> & <?php echo $custom_16; ?> are just incidently my custom field echo codes. I have over 150 custom fields working fine for user/listee options. The password protect code won't accept echos it seems as coded above. Thanks, Gene I have a series of string which can have a value or empty. I want to display them with echo. echo $string1 $string2 $string3; satisfies my need, as it shows available values, but with this method, I will get a PHP notice in my error_logs. What is your suggestion? Do I need to use "if (empty)" or "if(isset)"? The point is I have numerous strings and in each run only few of them have value. Hey guys,
Thank you in advance... here is my situation, I have a form with three (3) fields in it, the 'student name' is unlimited textfield with an "add more" button to it and I have two select fields ('number of shirts' and 'trophies') that depend on the number of entries for 'student name'...
I want to create the select fields based on this math, for as many 'student name' entries:
1- i want to have the select form for 'number of shirts' to be 0 up to that number... so if there are 6 'student name' entries, the select options will be 0,1,3,4,5,6,7
2- I want to have the select form for 'trophies' to be 5 'student name' entries to 1 'trophies', for example if there are 6 'student name' entries, the select options will be 0,1... if there are 13 entries, options will be 0,1,2... So if there are less than 5 'student name' entries, the select field will not show (hidden)
of course if there are no 'student name' entries, these two fields won't show up (hidden)
let me know if that make sense and ANY help or directions will be GREATLY APPRECIATED.
Thanks guys!
Alright, so I just started picking up PHP again and I have a pretty simple question. I have a html form that takes a string then writes it on another page. My problem is when I use quotations I'll get slashes in them on the page it writes the string on. Is there a way to clean that stuff up? Greetings! I have a CSV file that looks something like this: Quote ,,,,,,,,sdfsdf sdfsdf,,,,,,,,,,,,,,,,,,,,,,sdfsdfsdf:,,,,,,,,2011-04-27,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,dfgdfg,,fgh,,,,,gfh,,,,,,,,,,,,,,fghfgh,,,,,fghf,, fghfh,, fgh,,,,,,fhfgh,,,, Code: [Select] <?php $handle = fopen("csv.csv", "r"); while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) { echo "<pre>"; print_r($data); echo "<pre>"; } ?> Now this prints everything, could someone please provide me with an example of how I can ignore the "empty fields"? Thanks in advance! Hi, I searched and couldn't find a previous solution.. I'm supposed to take this existing long form and tweak it so it excludes empty fields when emailed.. Can anyone show me what would work for this code below? Any help would be greatly appreciated.. Sorry for the long code, i didn't know where to cut it off.. Code: [Select] <?php $EmailTo = Trim(stripslashes($_POST['EmailTo'])); $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $Subject = ""; // terms $terms_conditions_details = Trim(stripslashes($_POST['terms_conditions_details'])); // contact information $full_name = Trim(stripslashes($_POST['full_name'])); $title = Trim(stripslashes($_POST['title'])); $company = Trim(stripslashes($_POST['company'])); $billing_address = Trim(stripslashes($_POST['billing_address'])); $billing_city = Trim(stripslashes($_POST['billing_city'])); $billing_state = Trim(stripslashes($_POST['billing_state'])); $billing_zip = Trim(stripslashes($_POST['billing_zip'])); $phone = Trim(stripslashes($_POST['phone'])); $alt_phone = Trim(stripslashes($_POST['alt_phone'])); $how_did_you_hear = Trim(stripslashes($_POST['how_did_you_hear'])); // event information $event_date = Trim(stripslashes($_POST['event_date'])); $guests = Trim(stripslashes($_POST['guests'])); $event_start_time = Trim(stripslashes($_POST['event_start_time'])); $event_end_time = Trim(stripslashes($_POST['event_end_time'])); $event_address = Trim(stripslashes($_POST['event_address'])); $event_city = Trim(stripslashes($_POST['event_city'])); $event_state = Trim(stripslashes($_POST['event_state'])); $event_zip = Trim(stripslashes($_POST['event_zip'])); $event_type = Trim(stripslashes($_POST['event_type'])); $event_type_other = Trim(stripslashes($_POST['event_type_other'])); $event_theme = Trim(stripslashes($_POST['event_theme'])); $special_requests = Trim(stripslashes($_POST['special_requests'])); $budget = Trim(stripslashes($_POST['budget'])); $service_type = Trim(stripslashes($_POST['service_type'])); // wings & wingers $grilled_wings = Trim(stripslashes($_POST['grilled_wings'])); $buffalo_wings = Trim(stripslashes($_POST['buffalo_wings'])); $wingers = Trim(stripslashes($_POST['wingers'])); $wing_sauces1 = Trim(stripslashes($_POST['wing_sauces1'])); $wing_sauces2 = Trim(stripslashes($_POST['wing_sauces2'])); $wing_sauces3 = Trim(stripslashes($_POST['wing_sauces3'])); $wing_sauces4 = Trim(stripslashes($_POST['wing_sauces4'])); $wing_sauces5 = Trim(stripslashes($_POST['wing_sauces5'])); $wing_sauces6 = Trim(stripslashes($_POST['wing_sauces6'])); $wing_sauces7 = Trim(stripslashes($_POST['wing_sauces7'])); $wing_sauces8 = Trim(stripslashes($_POST['wing_sauces8'])); $wing_sauces9 = Trim(stripslashes($_POST['wing_sauces9'])); $wing_sauces10 = Trim(stripslashes($_POST['wing_sauces10'])); $wing_sauces11 = Trim(stripslashes($_POST['wing_sauces11'])); $wing_sauces12 = Trim(stripslashes($_POST['wing_sauces12'])); $wing_sauces13 = Trim(stripslashes($_POST['wing_sauces13'])); $wing_sauces14 = Trim(stripslashes($_POST['wing_sauces14'])); // party platters $chicken_finger_platter = Trim(stripslashes($_POST['chicken_finger_platter'])); $chicken_nugget_platter = Trim(stripslashes($_POST['chicken_nugget_platter'])); $chicken_wing_platter = Trim(stripslashes($_POST['chicken_wing_platter'])); // salads $caesar_salad = Trim(stripslashes($_POST['caesar_salad'])); $house_salad = Trim(stripslashes($_POST['house_salad'])); $cobb_salad = Trim(stripslashes($_POST['cobb_salad'])); $sea_breeze_salad = Trim(stripslashes($_POST['sea_breeze_salad'])); // appetizers $fresh_fruit_platter = Trim(stripslashes($_POST['fresh_fruit_platter'])); $chilled_vegetable_platter = Trim(stripslashes($_POST['chilled_vegetable_platter'])); $cocktail_shrimp = Trim(stripslashes($_POST['cocktail_shrimp'])); $tailgate_chips_platter = Trim(stripslashes($_POST['tailgate_chips_platter'])); $chips_and_salsa = Trim(stripslashes($_POST['chips_and_salsa'])); $spinach_artichoke_dip_platter = Trim(stripslashes($_POST['spinach_artichoke_dip_platter'])); $quesadilla_platter = Trim(stripslashes($_POST['quesadilla_platter'])); // entrees $bbq_ribs_platter = Trim(stripslashes($_POST['bbq_ribs_platter'])); $hawaiian_chicken = Trim(stripslashes($_POST['hawaiian_chicken'])); $mahi_over_rice = Trim(stripslashes($_POST['mahi_over_rice'])); // sandwiches $gourmet_slider_platter = Trim(stripslashes($_POST['gourmet_slider_platter'])); $mini_cheeseburger_platter = Trim(stripslashes($_POST['mini_cheeseburger_platter'])); $club_sandwich_platter = Trim(stripslashes($_POST['club_sandwich_platter'])); $turkey_wrap_platter = Trim(stripslashes($_POST['turkey_wrap_platter'])); $philly_cheese_platter = Trim(stripslashes($_POST['philly_cheese_platter'])); // dessert $chocolate_brownie_platter = Trim(stripslashes($_POST['chocolate_brownie_platter'])); $apple_crisp = Trim(stripslashes($_POST['apple_crisp'])); $mini_gourmet_cheesecakes = Trim(stripslashes($_POST['mini_gourmet_cheesecakes'])); //$10 meal deal $meal_deal_wings = Trim(stripslashes($_POST['meal_deal_wings'])); $meal_deal_grilled_chicken = Trim(stripslashes($_POST['meal_deal_grilled_chicken'])); $meal_deal_burger = Trim(stripslashes($_POST['meal_deal_burger'])); $meal_deal_lemonade = Trim(stripslashes($_POST['meal_deal_lemonade'])); $meal_deal_iced_tea = Trim(stripslashes($_POST['meal_deal_iced_tea'])); $meal_deal_sauces1 = Trim(stripslashes($_POST['meal_deal_sauces1'])); $meal_deal_sauces2 = Trim(stripslashes($_POST['meal_deal_sauces2'])); $meal_deal_sauces3 = Trim(stripslashes($_POST['meal_deal_sauces3'])); $meal_deal_sauces4 = Trim(stripslashes($_POST['meal_deal_sauces4'])); $meal_deal_sauces5 = Trim(stripslashes($_POST['meal_deal_sauces5'])); $meal_deal_sauces6 = Trim(stripslashes($_POST['meal_deal_sauces6'])); $meal_deal_sauces7 = Trim(stripslashes($_POST['meal_deal_sauces7'])); $meal_deal_sauces8 = Trim(stripslashes($_POST['meal_deal_sauces8'])); $meal_deal_sauces9 = Trim(stripslashes($_POST['meal_deal_sauces9'])); $meal_deal_sauces10 = Trim(stripslashes($_POST['meal_deal_sauces10'])); $meal_deal_sauces11 = Trim(stripslashes($_POST['meal_deal_sauces11'])); $meal_deal_sauces12 = Trim(stripslashes($_POST['meal_deal_sauces12'])); $meal_deal_sauces13 = Trim(stripslashes($_POST['meal_deal_sauces13'])); $meal_deal_sauces14 = Trim(stripslashes($_POST['meal_deal_sauces14'])); // box lunches $box_turkey_ruben = Trim(stripslashes($_POST['box_turkey_ruben'])); $box_blt_on_ciabatta = Trim(stripslashes($_POST['box_blt_on_ciabatta'])); $box_club = Trim(stripslashes($_POST['box_club'])); $box_ham_and_cheese = Trim(stripslashes($_POST['box_ham_and_cheese'])); $box_chipolte_shrimp_blt = Trim(stripslashes($_POST['box_chipolte_shrimp_blt'])); $box_turkey_bacon_ranch = Trim(stripslashes($_POST['box_turkey_bacon_ranch'])); $box_buffalo_chicken = Trim(stripslashes($_POST['box_buffalo_chicken'])); $box_veggie = Trim(stripslashes($_POST['box_veggie'])); $box_caesar_salad = Trim(stripslashes($_POST['box_caesar_salad'])); $box_house_salad = Trim(stripslashes($_POST['box_house_salad'])); $box_cobb_salad = Trim(stripslashes($_POST['box_cobb_salad'])); $box_sea_breeze_salad = Trim(stripslashes($_POST['box_sea_breeze_salad'])); // full service catering $theme_package = Trim(stripslashes($_POST['theme_package'])); $theme_package_information = Trim(stripslashes($_POST['theme_package_information'])); $reception = Trim(stripslashes($_POST['reception'])); $reception_information = Trim(stripslashes($_POST['reception_information'])); $specialty_stations = Trim(stripslashes($_POST['specialty_stations'])); $bar_beverage_service = Trim(stripslashes($_POST['bar_beverage_service'])); $bar_beverage_service_information = Trim(stripslashes($_POST['bar_beverage_service_information'])); $breakfast = Trim(stripslashes($_POST['breakfast'])); $breakfast_information = Trim(stripslashes($_POST['breakfast_information'])); $notes = Trim(stripslashes($_POST['notes'])); // payment $payment1 = Trim(stripslashes($_POST['payment1'])); $payment2 = Trim(stripslashes($_POST['payment2'])); $payment3 = Trim(stripslashes($_POST['payment3'])); $payment4 = Trim(stripslashes($_POST['payment4'])); $payment5 = Trim(stripslashes($_POST['payment5'])); $payment6 = Trim(stripslashes($_POST['payment6'])); // confirmation email $confirmation_subject = ""; $confirmation_body = "$full_name,\n\n Thank you for emailing us. A catering manager from your location will get in touch with you shortly.\n\n \n \n"; $Body = ""; $Body .= "CONTACT INFORMATION\n"; $Body .= "\nFull Name: "; $Body .= $full_name; $Body .= "\nTitle: "; $Body .= $title; $Body .= "\nCompany: "; $Body .= $company; $Body .= "\nBilling Address: "; $Body .= $billing_address; $Body .= ", "; $Body .= $billing_city; $Body .= ", "; $Body .= $billing_state; $Body .= ", "; $Body .= $billing_zip; $Body .= "\nPhone: "; $Body .= $phone; $Body .= "\nAlternate Phone: "; $Body .= $alt_phone; $Body .= "\nHow did you hear about us?: "; $Body .= $how_did_you_hear; $Body .= "\n"; $Body .= $terms_conditions_details; $Body .= "\n\nEVENT INFORMATION\n"; $Body .= "\nEvent Date: "; $Body .= $event_date; $Body .= "\nNumber of Guests: "; $Body .= $guests; $Body .= "\nEvent Start Time: "; $Body .= $event_start_time; $Body .= "\nEvent End Time: "; $Body .= $event_end_time; $Body .= "\nEvent Address: "; $Body .= $event_address; $Body .= ", "; $Body .= $event_city; $Body .= ", "; $Body .= $event_state; $Body .= ", "; $Body .= $event_zip; $Body .= "\nType of Event: "; $Body .= $event_type; $Body .= "\nType of Event: Other: "; $Body .= $event_type_other; $Body .= "\nEvent Theme: "; $Body .= $event_theme; $Body .= "\nSpecial Requests: "; $Body .= $special_requests; $Body .= "\nBudget: "; $Body .= $budget; $Body .= "\nType of Service: "; $Body .= $service_type; $Body .= "\n\nWINGS & WINGERS\n"; $Body .= "\nGrilled Wings: "; $Body .= $grilled_wings; $Body .= "\nBuffalo Wings: "; $Body .= $buffalo_wings; $Body .= "\nWingers: "; $Body .= $wingers; $Body .= "\nWing Sauces: "; $Body .= "$wing_sauces1, $wing_sauces2, $wing_sauces3, $wing_sauces4, $wing_sauces5, $wing_sauces6, $wing_sauces7, $wing_sauces8, $wing_sauces9, $wing_sauces10, $wing_sauces11, $wing_sauces12, $wing_sauces13, $wing_sauces14"; $Body .= "\n\nPARTY PLATTERS\n"; $Body .= "\nChicken Finger Platter: "; $Body .= $chicken_finger_platter; $Body .= "\nChicken Nugget Platter: "; $Body .= $chicken_nugget_platter; $Body .= "\nChicken Wing Platter: "; $Body .= $chicken_wing_platter; $Body .= "\n\nSALADS\n"; $Body .= "\nCaesar Salad: "; $Body .= $caesar_salad; $Body .= "\nHouse Salad: "; $Body .= $house_salad; $Body .= "\nCobb Salad: "; $Body .= $cobb_salad; $Body .= "\nSea Breeze Salad: "; $Body .= $sea_breeze_salad; $Body .= "\n\nAPPETIZERS\n"; $Body .= "\nFresh Fruit Platter: "; $Body .= $fresh_fruit_platter; $Body .= "\nChilled Vegetable Platter: "; $Body .= $chilled_vegetable_platter; $Body .= "\nCocktail Shrimp: "; $Body .= $cocktail_shrimp; $Body .= "\nTailgate Chips Platter: "; $Body .= $tailgate_chips_platter; $Body .= "\nChips and Salsa: "; $Body .= $chips_and_salsa; $Body .= "\nSpinach Artichoke Dip Platter: "; $Body .= $spinach_artichoke_dip_platter; $Body .= "\nQuesadilla Platter: "; $Body .= $quesadilla_platter; $Body .= "\n\nENTREES\n"; $Body .= "\nBBQ Ribs Platter: "; $Body .= $bbq_ribs_platter; $Body .= "\nHawaiian Chicken: "; $Body .= $hawaiian_chicken; $Body .= "\nMahi Over Rice: "; $Body .= $mahi_over_rice; $Body .= "\n\nSANDWICHES\n"; $Body .= "\nGourmet Slider Platter: "; $Body .= $gourmet_slider_platter; $Body .= "\nMini Cheeseburger Platter: "; $Body .= $mini_cheeseburger_platter; $Body .= "\nClub Sandwich Platter: "; $Body .= $club_sandwich_platter; $Body .= "\nTurkey Wrap Platter: "; $Body .= $turkey_wrap_platter; $Body .= "\nPhilly Cheese Platter: "; $Body .= $philly_cheese_platter; $Body .= "\n\nDESSERT\n"; $Body .= "\nChocolate Brownie Platter: "; $Body .= $chocolate_brownie_platter; $Body .= "\nApple Crisp: "; $Body .= $apple_crisp; $Body .= "\nMini Gourmet Cheesecakes: "; $Body .= $mini_gourmet_cheesecakes; $Body .= "\n\n$10 MEAL DEAL\n"; $Body .= "\nWings: "; $Body .= $meal_deal_wings; $Body .= "\nGrilled Chicken Breast: "; $Body .= $meal_deal_grilled_chicken; $Body .= "\nBurger: "; $Body .= $meal_deal_burger; $Body .= "\nLemonade: "; $Body .= $meal_deal_lemonade; $Body .= "\nIced Tea: "; $Body .= $meal_deal_iced_tea; $Body .= "\nWing Sauces: "; $Body .= "\n\nBOX LUNCHES\n"; $Body .= "\nSandwiches"; $Body .= "\nTurkey Ruben: "; $Body .= $box_turkey_ruben; $Body .= "\nBLT on Ciabatta Bread: "; $Body .= $box_blt_on_ciabatta; $Body .= "\nClub: "; $Body .= $box_club; $Body .= "\nHam and Cheese: "; $Body .= $box_ham_and_cheese; $Body .= "\n\nWraps"; $Body .= "\nChipolte Shrimp BLT: "; $Body .= $box_chipolte_shrimp_blt; $Body .= "\nTurkey Bacon Ranch: "; $Body .= $box_turkey_bacon_ranch; $Body .= "\nBuffalo Chicken: "; $Body .= $box_buffalo_chicken; $Body .= "\nVeggie: "; $Body .= $box_veggie; $Body .= "\n\nSalad"; $Body .= "\nCaesar Salad: "; $Body .= $box_caesar_salad; $Body .= "\nHouse Salad: "; $Body .= $box_house_salad; $Body .= "\nCobb Salad: "; $Body .= $box_cobb_salad; $Body .= "\nSea Breeze Salad: "; $Body .= $box_sea_breeze_salad; $Body .= "\n\nFULL SERVICE CATERING\n"; $Body .= "\nTheme Package: "; $Body .= $theme_package; $Body .= "\nInformation: "; $Body .= $theme_package_information; $Body .= "\nReception: "; $Body .= $reception; $Body .= "\nInformation: "; $Body .= $reception_information; $Body .= "\nSpecialty Stations: "; $Body .= $specialty_stations; $Body .= "\nBar/Beverage Service: "; $Body .= $bar_beverage_service; $Body .= "\nInformation: "; $Body .= $bar_beverage_service_information; $Body .= "\nBreakfast: "; $Body .= $breakfast; $Body .= "\nInformation: "; $Body .= $breakfast_information; $Body .= "\nNotes: "; $Body .= $notes; $Body .= "\n\nPAYMENT TYPE\n"; $Body .= "$payment1, $payment2, $payment3, $payment4, $payment5, $payment6"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>") && mail($EmailFrom, $confirmation_subject, $confirmation_body, "From: <$EmailTo>"); I have a form with a series of text boxes where the User enters specific data, be it text, numeric, or date/time. It is not mandatory to fill in every box, but when I submit the form to be put into a mysql table, I get errors such as "Incorrect time value: '' for column 'starttime' at row 1" "Incorrect decimal value: '' for column 'workkj' at row 1" How can I setup the mysql table to accept blank answers? Or is there something I need to do in php to fix this? Sorry if this is simple... I'm still learning. Thanks for the help! I dont understand why this simple validation im doing isnt working. I got rid of all my code and took it down to its simpliest form. I tried every debuging i can think of using echo's. If all fields are blank it performs as suspected and echos all fields are empty. but if i type something in one of the fields or all the fields at once it never goes onto the else statment. Is it possible to display everything a page is doing? in like true and false statements. if (isset($_POST['send_attack'])) { // checks if all fields are blank if(empty($_POST['jaffa'])) { echo "jaffa is empty <br />"; if(empty($_POST['staff_cannons'])) { echo "staff_cannons is empty <br />"; if(empty($_POST['transport_ships'])) { echo "transport_ships is empty <br />"; if(empty($_POST['bombers'])) { echo "bombers is empty <br />"; if(empty($_POST['mother_ships'])) { echo "mother_ships is empty <br />"; echo "all fields are empty"; }else{ echo "one or more fields has something in it"; }}}}}} Hi, i'm new here and hope i've finally found a forum where i can find the perfect solution for my questions.
Well since a year now i started to work with PHP and still now and then there are some things where i seize on. My question is on of those situations.
I have the following code:
if (isset($_POST)){ foreach ($_POST as $key => $value){ if (!empty($value)){ $update_rma_detail_stmt = $dbh->prepare("UPDATE rma_detail SET $key = ? WHERE rd_rma_nr = ?"); $update_rma_detail_stmt->bindParam(1, $value); $update_rma_detail_stmt->bindParam(2, $getadmrmaid); $update_rma_detail_stmt->execute(); } } }All i want is when there is an empty (not filled in) input field because it is not mandatory the foreach still continuous to the end. When i use if (!empty($value)){It still outputs these error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ' ' However, when i dont use i got an other error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' It is however so that the datetime is the very first empty field it come across when looping. I think my if (!empty($value)){ is doing the right thing but still gives error's on integers. Can it be? I allready tried to use trim() or array_filter() but because i previously never used it i dont know if i am doing it the right way so any help is welkom! Thanks! Edited by Raz3rt, 20 May 2014 - 02:56 AM. Hello friends, if i've textarea form or even input how to prevent visitors to write html codes inside it ? thanks I have two forms that I have created. I wonder if someone could point out where I am going wrong, all data is commented so it should be easier to understand. form1.php Code: [Select] <?php $digest = 0; $amount = 0; $trans_id = 0; $merchant = "so"; $remotepassword = "s0"; if ($_POST) { $digest_this = $_POST['trans_id'] + $_POST['amount'] + $remotepassword; //combine all my values to be md5'd $digest = md5($digest_this); //generate the md5 hash $amount = $_POST['amount']; //what I think I am doing here is posting the data so it can be retrived $trans_id = $_POST['trans_id']; //by a get request on from 2, this is where I need help $merchant = $_POST['merhcant']; $remotepassword = $_POST['remotepassword']; } // end $_POST ?> <form action="part2.php" method="post"> <p> <label for="trans_id">Invoice Number(s): </label> <input id="trans_id" type="text" name="trans_id" /><br /> <label for="amount">Amount Paying: </label> <input id="amount" type="text" name="amount" /><br /> <input value="Send" type="submit" /> <input type="reset" /> </p> </form> form2.php Code: [Select] <?php if ($_GET) { $digest = $_GET['digest']; //here I think I am retriving the data I sent with a post request $merchant = $_GET['merhcant']; //and then storing it in variables $remotepassword = $_GET['remotepassword']; $amount = $_GET['amount']; $trans_id = $_GET['trans_id']; } // end $_GET ?> <form action="https://www.secpay.com/java-bin/ValCard" method="post"> <p> <label for="firstname">First Name: </label> <input id="firstname" type="text" name="firstname" /><br /> <label for="lastname">Last Name: </label> <input id="lastname" type="text" name="lastname" /><br /> <label for="account">Account Number: </label> <input id="account" type="text" name="account" /><br /> <label for="housenumber">House Number/Name: </label> <input id="housenumber" type="text" name="housenumber" /><br /> <label for="postcode">Postcode: </label> <input id="postcode" type="text" name="postcode" /><br /> <label for="email">Email: </label> <input id="email" type="text" name="email" /><br /> <label for="notes">Notes: </label> <input id="notes" type="text" name="notes" /><br /> <!-- Here I have taken all the inputs from the form that are required to be sent --> <!-- and given the input_id names as the values required by the pay point servers --> <input name="callback" value="http://www.sol.co.uk/authorised;http://www.sol.co.uk/declined" type="hidden" /> <input name="merchant" value="<?php echo "$merhcant"; ?>" type="hidden" /> <!--here I am populating hidden fields with php script data--> <input name="remotepassword" value="<?php echo "$remotepassword"; ?>" type="hidden" /> <input name="req_cv2" value="true" type="hidden" /> <input name="options" value="test_status=true" type="hidden" /> <input name="digest" value="<?php echo "$digest"; ?>" type="hidden" /> <!-- Here I have defined all of the constant hidden values that never change --> <!-- Now in this section of the form I have defined the value that will change, combining the three fields --> <!-- that are required in order to create the digest value --> <input value="Send" type="submit" /> <input type="reset" /> </p> </form> Thanks for looking, I think its something basic im missing, first time doing this if you hadnt of guessed Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: I apologize in advance, I know pretty much nothing about PHP - don't hate me, please! But I'm working on a form mailer, and it functions, but what I don't like is it leaves all the text fields, blank or not, in my email, which makes it difficult for my client to read, so theres a long list of txt field1: another text field: blah blah: all the way down the email - and I want it gone! haha. I've researched how to do this, but basically, I have no idea how to implement it into my code and don't have time right now to up and learn PHP. My code is as follows: Code: [Select] <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> IT was a very simple copy-paste form, but I have no idea what on earth I'm doing. If anyone has any ideas I would GREATLY appriciate the help! Thanks! -Austin Hi guys! New to the community and hope to learn a lot here! Here is some background info and what I want to do, and what I know. I have been building websites for years, and I am familiar with Actionscript 3.0. And I have successful ran a few wordpress websites. What I am trying to do right now however is modify this form script I found, to only email the data when the field isn't left blank. It's stumping me because the actual "message" that ends up being the body of the email is a variable. And form what I can tell I can't figure out how to put if statements into it. If anyone can take a look at this script and give me any pointers you would be awesome. Code: [Select] <?php //trying to store the date in a separate variable only when it's not blank if ($_POST['starttime'] == '') { //nothing; } else { $showStartTime == "Start time: " . $_POST['starttime'] . ""; } if ($_POST['finishtime'] == '') { //nothing; } else { $showFinishTime == "Finish time: " . $_POST['finishtime'] . ""; } // Read POST request params into global vars $to = $_POST['to']; $from = $_POST['from']; $name = $_POST['name']; $company = $_POST['company']; $newcustomer = $_POST['newcustomer']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $subject = ("Event Rental for " . $name . ""); $description = $_POST['description']; $phone = $_POST['phone']; $message = (" Name: " . $name . " Company or Organization: " . $company . " Phone Number: " . $phone . " Email Address: " . $from . " Street Address: " . $address1 . " " . $address2 . " New Customer: " . $newcustomer . " Customer From: " . $_POST['howyouheard'] . " Interested in: SkyLoft " . $_POST['whichspace'] . " Date: " . $_POST['date'] . " Day of Week: " . $_POST['dayofweek'] . " " . $showStartTime . " " . $showFinishTime . " Number of Guests: " . $_POST['Guests'] . " Format: " . $_POST['format'] . " Occasion: " . $_POST['Occasion'] . " Optional Needs: " . $_POST['dj'] . " " . $_POST['tables'] . " " . $_POST['chairs'] . " " . $_POST['eventbanner'] . " " . $_POST['pasoundsystem'] . " Message: " . $description . " "); // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; } // Send the message $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p><b>Thank you for your interest in SkyLofts!</b> <br>You should recieve a verification in your inbox that we recieved your request. We will contact you as soon as possible and hopefully be able to answer any questions you may have! You can also contact us via phone 410-791-6699, or toll-free 1-800-344-0410.</p>"; } else { echo "<p>There was an error when processing your request. Please try again.</p>"; } ?> I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me:
<!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html>Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards! Edited by mac_gyver, 19 January 2015 - 09:37 PM. code tags around posted code please Hi i would like to know what is the best way to check if a textarea or an input box is empty. Is the empty function effective? Hi
How can limit only required input fields cannot be empty.
<form name="test" method="post" action="test.php"> <label for="quest"> <input type="text" name="quest" /> <!-- REQUIRED --> </label> <label for="answers"> <input type="text" name="answers[]" /> <!-- REQUIRED --> </label> <label for="answers"> <input type="text" name="answers[]" /> <!-- REQUIRED --> </label> <label for="answers"> <input type="text" name="answers[]" /> </label> <label for="answers"> <input type="text" name="answers[]" /> </label> <label for="answers"> <input type="text" name="answers[]" /> </label> <label for="submit"> <input type="submit" name="submit" value="Submit" /> </label> </form>Following function working only on all empty input fields, i need help to enable button when required fields is not empty. $(document).ready(function() { var $submit = $("input[type=submit]"), $inputs = $('input[name=quest], input[name=answers[]]'); function checkEmpty() { // filter over the empty inputs return $inputs.filter(function() { return !$.trim(this.value); }).length === 0; } $inputs.on('keyup', function() { $submit.prop("disabled", !checkEmpty()); }).keyup(); // trigger an initial blur }); I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug |