PHP - Exclude Empty Fields In Email
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>"); Similar TutorialsA select query I've written joins three tables. The query works fine, pulling up a users table, a table for specials advertising that are entered by members, a and a third table the identivies members who have joined a customer application.
A page displays listing all the entries who have joined the customer application, their names, address, etc display but if they have not set up their special advertising, then the fields for that table display NULL.
I have tried an If and an ifelse to not display text (you can see in the code the HTML Hours of Operation: and Specials:). Thee field I am using to differentiate is "m_primeID", it is an intiger field. The if statement I've written is follows.
if( $row["$m_primeID"] == 'NULL' ) { $company .= ""; } elseif( $row["$m_primeID"] <> 'NULL' ) { $company .= "<b>Hours of Operation:</b><br>" . ($row["m_coupon_title"]) . "<br /><br />\n"; $company .= "<b>Special:</b><br>" .($row["m_coupon_desc"]) . "<br /><br />\n"; }Here is a screen shot of part of the joined tables. This screen shot show the Null on the joined tables that don't have customer advertising set up. Any Ideas Attached Files Screen-Shot-of-Join.jpg 108.65KB 0 downloads This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=317758.0 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'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 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. 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?? 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 Below is the code I'm using, and I would like for when the information is sent to email that it omits empty fields including the field name. I'm not real sure on how to do this. Any help would be great!!!! Thanks!!!!! Code: [Select] ]<?php $SendFrom = "Form Feedback <feedback@yourdomain.com>"; $SendTo = "feedback@yourdomain.com"; $SubjectLine = "Feedback Submission"; $ThanksURL = "thanks.html"; //confirmation page foreach ($_POST as $Field=>$Value) $MsgBody .= "$Field: $Value\n"; $MsgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" . $_SERVER["HTTP_USER_AGENT"]; $MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES); //make safe mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); header("Location: $http://www.yourdomain.org"); ?> [/code I would like to send an email when % is >than 50%, if so get fields from Txt fiel and fields from DB and send an email to the address in the txt file.
<html> <head><title>Email Alert</title></head> <body> <?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output mysql_connect("ip","user","pass") or die(mysql_error()); //mysql_select_db("DB") or die(mysql_error()); //$sql = "SELECT * from pool"; $sql = mysql_db_query ("demo", "select * from pool "); while ($row = mysql_fetch_assoc($sql)) { $sql = "SELECT '%' FROM pool Where >= 50 "; { //echo $row->number; $percent = $row['%'] ; $pool2 = $row['pool']; $balance = $row['balance']; /////////////////////////// //data from file ////////// ////////////////////////// $file = fopen('EmailAndPool2.csv', 'r'); $fields = array(); if ($file) { while (($data = fgetcsv($file)) !== false) { if(empty($fields)) { $fields = $data; continue; } $row = array_combine($fields, $data); // Format output conveniently with sprintf $output = sprintf("%s Pool %s email.\n", $row['pool'], $row['email']); echo $output; } fclose($file); $pool1 = $row['pool']; //while ($pool2 == $pool1 and $percent > "50") $pool2 =$row['pool2']; $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'xxxxxxxxx; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'xxxxxxxxxxxxxxxxx'; // SMTP username $mail->Password = 'xxxxxxxxxxxxxxxx; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->FromName = 'Support'; $mail->addAddress ($row['email']); //$mail->addAddress = $members; //$mail->addCC('xxxxxxxxxxx'); //$mail->addCC('xxxxxxxxxxxxxxxx'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); $mail->Subject = 'test'; $mail->Body = 'test '; $email_from = 'xxxxxxxxxxxx'; } if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } ?> </body> </html>Thank you Hi there, I'm trying to output the form data into the email title, how I've attempted to do this is below: <?php if(isset($_POST['submit'])) { $to = 'message@website.com' ; $subject = '$song - $message - $name; //THIS BIT HERE I NEED WORKING... $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table> <tr><td>Name</td><td>".$_POST['name']."</td></tr> <tr><td>Message</td><td>".$_POST['message']."</td></tr> <tr><td>Song</td><td>".$_POST['song']."</td></tr> </tr></table>" ; mail($to, $subject, $message, $headers); header('Location: song-requests-success.php'); } ?> I keep getting errors. Many thanks I've put together a very simple form & processing script for my site.. Everything works great except the body of the email i receive when the form is submitted contains everything but the info that has been entered into the fields. I'm sure it's something simple that I'm overlooked, but I'm officially stumped. What am I doing wrong here? <?php $mymail = 'ordietryingodt@yahoo.com'; $cc = 'New Recruit To Add!'; $BoDy = ' '; $FrOm = 'FROM:' .$_POST['t1']; $FrOm .= 'Reply-To:' .$_POST['t1']; $FrOm .= 'X-MAILER: PHP'.phpversion(); $BoDy .= 'Quake Live Name: '; $BoDy .= $_POST['t1']; $BoDy .= "\n"; $BoDy .= 'Age: '; $BoDy .= $_POST['t2']; $BoDy .= "\n"; $BoDy .= 'Residing Country: '; $BoDy .= $_POST['t3']; $BoDy .= "\n"; $BoDy .= 'Favorite Game Type: '; $BoDy .= $_POST['t4']; $BoDy .= "\n"; $send = mail("$mymail", "$cc", "$BoDy", "$FrOm"); if($send) { echo '<html><head>'; echo '<meta http-equiv="refresh" content="0;URL=/submitted.htm">'; echo '</head><body>Email send....'; echo '</body></html>'; } ?> HTML code: Code: [Select] <form method="post" action="viewpage.php?page_id=5"> Email: <input name="email" type="text"><br> Full Name: <input name="name" type="text"><br> Age: <input name="age" type="text"><br> Summoner Name: <input name="summon" type="text"><br> Do you have vent? <input name="vent" type="text"><br> Do you have a mic? <input name="mic" type="text"><br> How often can you be on? <input name="online" type="text"><br> What level are you? <input name="level" type="text"><br> Who do you like to play as? <input name="champs" type="text"> </form><br> Can you help donate to the clan for vent and the site?<br> <textarea name="name" rows="7" cols="25"></textarea><br> Before you say anything about the PHP not scripted to do all fields, I already know this I'm trying to figure out how to send multiple ones in one message: PHP Code: Code: [Select] <?php if (isset($_POST['submit'])) { $to = "hidden for privacy"; $subject = "LoL Recruitment"; $email = $_REQUEST['email'] ; $message = ($_REQUEST['name'], $_REQUEST['age']) ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) { print "Your mail was sent successfully"; } else { print "We encountered an error sending your mail"; } } ?> I'm willing to bet my Code: [Select] $message = ($_REQUEST['name'], $_REQUEST['age']) ;if FAR wrong I made a script to grab the data between these tags on my page: Code: [Select] <td class="numbers"> </td> It shows only the numbers and that's what I want (see Ex: ) but if I view the source code it shows this: Code: [Select] Andreea - <td class="numbers">111</td><br /> Claudia - <td class="numbers">30</td><br /> Daniel - <td class="numbers">37</td><br /> Adela - <td class="numbers">4</td><br /> Is there a way to display the result without those tags ? Ex: Andreea - 111 Claudia - 30 ............ As you can see, I only need the numbers, there's nothing else inside those tags. I want to run a query on table 1 but exclude records if the field v3 matches the field "mrn" in table 2: I was told to use LEFT OUTER JOIN but this doens't work: Code: SELECT * FROM pts LEFT OUTER JOIN p_list ON pts.v3 = p_list.mrn WHERE pts.v3 IS NULL When I do that nothing is displayed. I don't know if the "IS NULL" term is the problem. Can someone help me with what the php code is to make that query work? Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } Hi, I have this menu code which displays a drop down menu: <ul> <li><a href="<?php echo URL_PUBLIC; ?>">Home</a></li> <?php function submenu($list, $ul){ if($ul){ echo " <ul>";} foreach($list->children() as $newList){ echo ' <li>'.$newList->link($newList->title, (in_array($newList->slug, explode('/', $newList->url)) ? ' class="current"': null)); if ($newList->childrenCount() > 0) { submenu($newList, true); }else{echo "</li>";} } if($ul){echo " </ul></li>";} } submenu($this->find('/'), false); ?> <br style="clear: left" /> </ul> I am trying to exclude certain menu items based on their slug. I have this code, but can't work it into the above: $omit_pages = array('page1', 'page2'); if (in_array($menu->slug, $omit_pages)) { continue; } Does anyone have any ideas how I can work it in? Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322237.0 Hey guys, I'm a little confused to how I can do this.
I am basically wanting to give my first column a 'NOT NULL AUTO_INCREMENT' and give each row it's own 'id'. The issue I am having is that the script I am using truncates the whole SQL table with a CSV file that is cron'd daily to update data.
I am currently using this script:
<?php $databasehost = "localhost"; $databasename = ""; $databasetable = ""; $databaseusername=""; $databasepassword = ""; $fieldseparator = ","; $lineseparator = "\n"; $enclosedbyquote = '"'; $csvfile = "db-core/feed/csv/csv.csv"; if(!file_exists($csvfile)) { die("File not found. Make sure you specified the correct path."); } try { $pdo = new PDO("mysql:host=$databasehost;dbname=$databasename", $databaseusername, $databasepassword, array( PDO::MYSQL_ATTR_LOCAL_INFILE => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); } catch (PDOException $e) { die("database connection failed: ".$e->getMessage()); } $pdo->exec("TRUNCATE TABLE `$databasetable`"); $affectedRows = $pdo->exec(" LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." REPLACE INTO TABLE `$databasetable` FIELDS OPTIONALLY ENCLOSED BY ".$pdo->quote($enclosedbyquote)." TERMINATED BY ".$pdo->quote($fieldseparator)." LINES TERMINATED BY ".$pdo->quote($lineseparator)." IGNORE 1 LINES"); echo "Loaded a total of $affectedRows records from this csv file.\n"; ?>Is it possible to amend this script to ignore my first column and truncate all of the data in the table apart from the first column? I could then give all of the rows in the first column their own ID's any idea how I could do this? I am still very nooby so please go easy on me |