PHP - How Can I Test The $_post Array To See If It Is Set By The Form
I have a form that is populating fields based on a database query. I am then trying to update the database based on any changes made in the form and passed through a POST action.
The problem I am having is with the block where I declare short variable names for the $_POST variables that will be passed when the user hits the submit button. For each variable declaration I get an error message like this: Quote Encountered error: 8 in mbr_profile_updt_form.php, line 130: Undefined index: email I have tried testing the $_POST variable using the isset function but it apparently is set but empty. What would be a good way to test to see if the user has pressed the submit button before I go into the processing block that is intended to handle those values from the form? Here is where my code is at right now: Code: [Select] if (!isset($_POST)) { throw new Exception('You have not filled the form out completely - please go back' .' and try again.'); } else { //filled in so create short variable names $email=$_POST['email']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; Similar TutorialsIs there an easy way to dump out the contents of a $_POST array and display them on my screen? (I'm trying to get more comfortable with what is stored in the $_POST array and how it is structured.) Thanks, TomTees Hi. First timer here. I'm trying to iterate through 5 arrays in a foreach loop. Yep, I know you'll say just use a counter that increments. Sadly, that gives me horrendous results! So, I am using the next & current methods of arrays. Thing is, it gives me bad results ( items that weren't even chosen on the next page ), or it leaves the first couple of items out. I did this : Code: [Select] <?php $ID = array(); $NAME = array(); $PRICE = array(); $QUANT = array(); $checkCount = 0; foreach (array_keys($_POST) as $key) { $$key = $_POST[$key]; $iPos = strpos($key, "ID"); $nPos = strpos($key, "NAME"); $pPos = strpos($key, "PRICE"); $qPos = strpos($key, "QUANT"); $cPos = strpos($key, "CHECK"); if ($iPos !== false) { $ID[] = $$key; } else { //echo "The string ID was not found in the string "; } if ($nPos !== false) { $NAME[] = $$key; } else { //echo "The string NAME was not found in the string "; } if ($pPos !== false) { $PRICE[] = $$key; } else { //echo "The string PRICE was not found in the string "; } if ($qPos !== false) { $QUANT[] = $$key; } else { //echo "The string QUANT was not found in the string "; } if ($cPos !== false) { $checkCount++; if ($checkCount == 1) { echo "Product ID <input type = 'text' name = 'ID" . current($ID) . "' value = '" . current($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . current($NAME) . "' value = '" . current($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . current($PRICE) . "' value = '" . current($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . current($QUANT) . "' value = '" . current($QUANT) . "'></br>"; } if ($checkCount > 1) { echo "Product ID <input type = 'text' name = 'ID" . next($ID) . "' value = '" . next($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . next($NAME) . "' value = '" . next($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . next($PRICE) . "' value = '" . next($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . next($QUANT) . "' value = '" . next($QUANT) . "'></br>"; } } else { //echo "The string CHECK was not found in the string "; } } ?> You will see I did all the processing under the CHECK if statement, the reason for this is, it is easier to identify the items ordered because they have been checked on the previous page. How do I post a for loop array in the next page. I am printing Question ID and choices for these and would like the for loop to print Question ID and choice that are checked for these. If the choice is ticked then it shoul return a 1 if the choice is empty then it should print 0. and I would like to insert this to a new table. How would I do this. Code: [Select] $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; ?> <br> <?PHP for ($i =1; $i < 5; $i++) { echo "<input type=\"checkbox\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}"; $intnumber++; } this is my form that print the question and it works fine. Code: [Select] <?PHP foreach ($_POST["Que_ID"] as $question) { $_POST["choice"] = $choice; echo "Question id: ".$question. $choice"<br />"; This is the post code but I know I need to do so much more but not sure how? Ayone help me or direct me to a source or tutorial or something. I am trying to post while loop array. But I dont know how to do this and I used foreach and it works for each array but doesnt loop this. My table has Que_ID, Question, choice1, choice2, choice3 and choice 4. I would like to do something like.. For each Que_id (choice1, choice2, choice3 , choice4), this should be looped for each que_id so far I have Code: [Select] $counter = 1; while( $info = mysql_fetch_array( $sqll )) //)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; How would go on to posting these while loop and display Que_ID and all the choices that are ticked for this que_ID and if its not ticked then its 0. How do I assign the entire $_POST array to a varible? This code isn't working... <?php echo 'FormHandler'; class FormHandler{ private $formValues = array(); $this->formValues = $_POST; } ?> TomTees I need to email the form http://keegenk.com/providenceltddesign/ to myself. Right now, the email is sending and the confirmation page comes up, but the email does not have any of the data that should be collected by the form. I'll attach the php file that I'm using to capture the variable and send it to the email address. Any and all help is appreciated. Thanks a bunch Well I have a script file that loads lots of info from a form using $_POST[] method, which is quite tedious: Code: [Select] $act = $_POST["act"]; $page = $_POST["page"]; $id = $_POST["id"]; $category = $_POST["category"]; $itemname = $_POST["itemname"]; $description = $_POST["description"]; $imageurl = $_POST["imageurl"]; $existingimageurl = $_POST["existingimageurl"]; $function = $_POST["function"]; $target = $_POST["target"]; $value = $_POST["value"]; $shop = $_POST["shop"]; $price = $_POST["price"]; $tradable = $_POST["tradable"]; $consumable = $_POST["consumable"]; I was wondering if there is a way to write one or two simple lines of code to load all variables stored in superglobal array $_POST[] efficiently. The point is to store all values within $_POST[] to an array called $item[], what I was thinking about is: Code: [Select] foreach($_POST = $key as $val){ $item['{$key}'] = $val; } Seems that its not gonna work, so I wonder if anyone of you have ideas on how I am able to simplify my code with 10-20 lines of $_POST[] to just 2-3 lines. Please do lemme know if this is possible, thanks. So ive created a forum that I got handling several different approvals. (it is used to approve or decline all submitted notes) it works fine and it even submits fine im at the part know where i process the information and do something with it, below is my form: <form action="course_proccess.php?action=approve" method="post"> <table align="left" border="1" cellspacing="0" cellpadding="3"> <tr> <td><b>Author</b></td> <td><b>File name</b></td> <td><b>Download</b></td> <td><b>Suggested catagory</b></td> <td><b>Select Catagory</b></td> <td>Approve</td> </tr> <td><input type="text " disabled="disabled" name="tr1_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr1_name" value="A lot of my skills set back"</td> <td><a href= /uzEr%20Upl0ds/cache.zip > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr1_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr1_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <td><input type="text " disabled="disabled" name="tr2_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr2_name" value="MM"</td> <td><a href= /uzEr%20Upl0ds/Michael Heintzman.doc > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr2_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr2_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <input type="hidden" name="rowCount" value="2"> <tr> <td><input type="submit" name="sendData" value="send"/></td> </tr> </table> </form> so what I do in my process file is I have a for loop for all of the "TR's" in the table and if it is approved I have an if statment and then I want to add db stuff my problem is my $_POST's are returning blank and I have no idea why. Can someone please assit me with this? (p.s i have debugged and it does get into the if approve == 1 statment. if(isset($_GET['action'])){ if ($_GET['action'] == "approve"){ if(isset($_POST['sendData'])) { $dataArray = array(); $row_count = $_POST['rowCount']; for($i=1;$i<$row_count;$i++) { $approven = "tr".$i."_approve"; $approve = $_POST[$approven]; if($approve == 1) { //Move the info over to "approved files" and delete it out of newnotes $author = "tr".$i."_author"; $location = "tr".$i."_location"; $catagory ="tr".$i."_scatagory"; $filename = "tr".$i."_name"; $submitedby = $_POST['author']; die($submitedby); $dataArray[]=array('author'=>$author,'fileName'=>$fileName,'Catagory'=>$catagory,'location'=>$location); var_dump($dataArray); }else{ //Email user saying they did not recive credits AND delete the entry } } if(!empty($dataArray)) { //now do what you want with the dataArray... var_dumb($dataArray); } } } 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. Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. Hi the above title explains it all.How to output a post array which has been given input using forms.I know you can do it my echo but what about print() Thanks Hello there! I made a contact-form with PHP but the e-mails go directly into the spam folder. Then I ran a test on http://www.mail-tester.com and I got some errors. As you can tell, I am new to PHP and I don't know what to do. I appreciate any help! Errors: 1. HTML_MIME_NO_HTML_TAG HTML-only message, but there is no HTML tag 2. MIME_HTML_ONLY Message only has text/html MIME parts 3. MISSING_DATE Missing Date: header 4. "Your message is not signed by DKIM" 5. "There is no SPF record. Please add (number).easyname.com to your DNS zone file."
Here is my PHP: <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: mywebsite.com'; $to = 'someone@something.net'; $subject = 'Subject-line'; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html\r\n"; $headers .= 'From: '. $email. "\r\n" . $headers .= "Reply-To: ". $email. "\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); $message = nl2br($message); $status = mail($to, $subject, $message, $headers); if($status) { echo '<p>Your Message has been send!</p>'; } else { echo '<p>Something went wrong. Please try again.</p>'; } ?> Here is my HTML: <div class="contact-form"> <form id="contact-form" method="post" action="contact-form-handler.php"> <input name="name" type="text" class="form-control" placeholder="Your Name" required> <br> <input name="email" type="email" class="form-control" placeholder="Your Email"> <br> <textarea name="message" class="form-control" placeholder="Message" rows="40" required></textarea><br> <input type="submit" class="form-control" value="SEND MESSAGE"> </form> </div>
I tried many things but nothing really worked. Also, I am a noob at PHP so I am kind of lost. Thanks for your help! how to cross reference $_POST array 'checkboxes[]' with mysql field I have a form that is submitted so the user can select which results to print. but I am having problems getting the results to show correctly. how do I correctly cross reference the form data with the mysql Code: [Select] $getRequests = mysql_query("SELECT * FROM requests WHERE `customer_email`='{$_SESSION['FM_user']}'"); while($request = mysql_fetch_assoc($getRequests)) { if (!in_array($request['request_id'],array($_POST[request]))) { echo '<li style="font-size:10px; border-bottom: 0.1em solid #D0D0D0"> <div class="leftfloat"> <input type="checkbox" name="request[]" value="',$request['request_id'],'"> </div> <div class="leftfloat"> <em>',$request['request_id'],'</em> </div><div class="leftfloat"> | </div> <div class="leftfloat"> <em>',$request['customer_name'],'</em> </div><div class="leftfloat"> | </div> <br style="clear:both"> </li>'; } } There's probably an obvious reason but I can't seem to find it... I start with the $_POST array, received from a form: Code: [Select] array(9) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" ["button"]=> string(38) "updateColumnName=EnvironmentID;Value=1" } I get the button value from the array, and unset the button array value. Code: [Select] function load_POST($name) { //returns value and removes it from $_POST array. returns NULL if not existing. $debug = 0; if ( $debug == 1 ) { $backtrace = backtrace(); echo __FUNCTION__."()"; echo " <i>called by ".basename($backtrace[1]['file'])."</i><br/>\n"; } $post = NULL; if( array_key_exists($name, $_POST) ) { $post = urldecode($_POST[$name]); if ( $debug == 1 ) { echo "post $name, value: $post<br/>\n"; } } else { if ( $debug == 1 ) { echo "post $name: doesn't exist<br/>\n"; } } unset($_POST[$name]); return $post; } $_POST is now: Code: [Select] array(8) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" } Then I create the object to assign the values to: Code: [Select] object(Environment)#1 (9) { ["EnvironmentID"]=> NULL ["Name"]=> NULL ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) } So far so good Then, for each remaining $_POST value, I update the Object accordingly: First one, parametername: Name, parameter: KTN Code: [Select] object(Environment)#1 (10) { ["EnvironmentID"]=> NULL ["Name"]=> string(3) "KTN" ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) ["ColumnName=EnvironmentID;Value=1"]=> object(stdClass)#3 (1) { ["ColumnName"]=> string(1) "1" } } And there we have the problem, for some reason the button value is added to the object somehow... Any ideas? Thanks in advance! Hi All, I am having a bit of difficulty with a form I've built that has some PHP elements in it. The issue is it is just not sending the values (which are in hidden fields). Code is: Code: [Select] while($row = mysql_fetch_array($result)){ echo '<tr style="padding: 15px;">'; echo '<td>' . $row['product_id'] . '</td>'; echo '<td>' . $row['name'] . '</td>'; echo '<td>' . $row['catalogue_id'] . '</td>'; ?> <td> <form method="post" enctype="multipart/form-data" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> <!--Hidden Field Checks to see if form has already been sent--> <input type="hidden" name="editform" value="Y"> <!--Hidden Fields for Edit Job--> <input type="hidden" name="prodid" value="<?php echo $row['product_id'] ?>"> <input type="hidden" name="prodname" value="<?php echo $row['name'] ?>"> <input type="hidden" name="catalogue_id" value="<?php echo $row['catalogue_id'] ?>"> <input type="hidden" name="full_description" value="<?php echo $row['full_description'] ?>"> <input type="submit" name="Edit" value="<?php _e('Edit', 'pmimp_trdom' ) ?>" /> </form> </td> Would it have something to do with splitting up the php tags? Any help would be apprecited! Thanks! This is just a snippet of my code. The php script itself is called test.php and so it calls itself once the form is submitted. I keep having problems retrieving the data back correctly; I am testing in retrieving the data on the same script from the same page before retrieving the POST data from another webpage. If $decimalSum is a variable that assigns a value that is hard-coded then I would be able to retrieve the same value. However, if the value is computed I can not retrieve it unless I click on the "Find" button twice. This is such a strange behavior and I don't know why. Does anyone have any suggested solutions to this? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <?php echo '<form enctype="multipart/form-data" method="post" action="test.php">'; echo ' <label for="_firstName">First name : </label>'; echo ' <input type="text" id="_firstName" name ="_firstName">'; echo ' <input type="checkbox" value="1" name="_firstNameChecked"/>'; echo ' <label for="_middleName">Middle name : </label>'; echo ' <input type="text" id="_middleName" name ="_middleName">'; echo ' <input type="checkbox" value="1" name="_middleNameChecked" />'; echo ' <label for="_lastName">Last name : </label>'; echo ' <input type="text" id="_lastName" name ="_lastName">'; echo ' <input type="checkbox" value="1" name="_lastNameChecked" />'; echo '<br />'; echo '<input type="submit" name="Find" value="Find" />'; $firstNameChecked = intval(($_POST['_firstNameChecked'])); $middleNameChecked = intval(($_POST['_middleNameChecked'])); $lastNameChecked = intval(($_POST['_lastNameChecked'])); $decimalSum = (int)((2*2*2)*$firstNameChecked + (2*2)*$middleNameChecked + (2*1)*$lastNameChecked); //$decimalSum = 28; echo '<br />'; echo '$decimalSum = ' . $decimalSum . '<br />'; echo '<input type="hidden" name="_decimalSum" value = "' . $decimalSum . '" />'; $decimalSum2 = ($_POST['_decimalSum']); echo '$decimalSum2 = ' . $decimalSum2 . '<br />'; echo '</form>'; echo '</body>'; echo '</html>'; ?> Hi there I'm trying to make this form submit...but alas, is to no avail .... i have two forms on top of each other one of them is: Code: [Select] <form name="entries_form" method="post" action="index.php"> <table> <tr> <th><label>Date</label></th> <th><label>From</label></th> <th><label>To</label></th> <th><label>Break</label></th> <th><label>Hours</label></th> <th><label>Required Hours</label></th> <th><label>Notes</label></th> </tr> <tr> <td> <input name="Date" type="text" id="Date" /> </td> <td> <input name="From" type="text" id="From" /> </td> <td> <input name="To" type="text" id="To" /> </td> <td> <input name="Break" type="text" id="Break" /> </td> <td> <input name="Hours" type="text" id="Hours" /> </td> <td> <input name="Rqrd_hrs" type="text" id="Rqrd_hrs" /> </td> <td> <input name="Notes" type="text" id="Notes" /> </td> <td> <input type="submit" name="Save" value="Save" id="Save" style="background-color:#7A70A4;" /> </td> </tr> </table> </form> to post i'm using this code (to much over the top maybe): Code: [Select] <?php $session = new Session(); $u_id = $session->get('id'); //to get the user id from session if(isset($_POST['submit']) == 'Save'){//form's button name is Save $entry->user_id = $user_id = $u_id; $entry->date = $date = trim(strtolower($_POST['Date'])); $entry->start_time = $start_time = trim(strtolower($_POST['From'])); $entry->end_time = $end_time = trim(strtolower($_POST['To'])); $entry->breaks = $break = trim(strtolower($_POST['Break'])); $entry->total_hours = $total_hours = trim(strtolower($_POST['Hours'])); $entry->reqd_hours = $required_hours = trim(strtolower($_POST['Rqrd_hrs'])); $entry->notes = $notes = trim(strtolower($_POST['Notes'])); $entry->add_entry(); }else die("Not Posted"); ?> the add entry() function does the following: Code: [Select] public function add_entry(){ global $database; $sql = "INSERT INTO sheetentries ("; $sql .= "user_id, date, start_time, end_time, break, required_hours, total_hours, notes"; $sql .= ") VALUES ('"; $sql .= $this->user_id ."', '"; $sql .= $this->date ."', '"; $sql .= $this->start_time ."', '"; $sql .= $this->end_time ."', '"; $sql .= $this->breaks ."', '"; $sql .= $this->reqd_hours ."', '"; $sql .= $this->total_hours ."', '"; $sql .= $this->notes ."')"; $database->query($sql); } the user_id or $u_id brought from the session when the user loggs in: Code: [Select] $u_id = $session->get('id'); anyway, whenever i try submitting the form nothing happens, what am i missing,,, thanks in advance My form values are not posting on my thankyou.php page. I'm sure it's a simple fix. Here's some code from reservation.php . form action="CGI/gdform.php" method="post" enctype="application/x-www-form-urlencoded" name="formres" id="formres"> <input type="hidden" name=" redirect" value="ThankYou.php"> <label><span class="style12">Your Name: <input type="text" name="txtName" id="Name" /> </span></label> ... <p class="style12"><span id="sprytextfield10"> <label>Date of Special Event: <input type="text" name="DateReq" id="DateReq" /> </label> <?php $txtName = $_GET[txtName]; ... $DateReq = $_GET[DateReq]; ?> </form> On my thankyou.php: <body> <?php $txtName = $_POST[txtName]; ... $DateReq = $_POST[DateReq]; ?> and a little lower down... <?php echo $txtName ?> ... <?php echo $DateReq ?> Any reason why the thank you page isn't calling the values? I exhaustively checked it against a working form I have on another site, and the code seems to be, well, identical. Not getting an error, just get empty space where the values should be. can someone visually just read through my code and let me know if this looks like it'll work? I'm not getting any errors in my IDE so now I want to double check the structure <?php require_once '/usr/local/cpanel/3rdparty/lib/php/Mail.php'; $db_server = 'localhost'; $db_user = '-----'; $db_pass = '-----'; $dbc = mysql_connect ($db_server, $db_user, $db_pass); if (!$dbc) { die(mysql_error()); header ('Location: /contact'); exit; } if ($_POST['contactsent'] != 'yes') { header ('Location: /contact'); exit; } else { if (is_array($_POST)) { foreach ($_POST as $key => $value) { $_POST[$key] = mysql_real_escape_string(stripslashes($value)); } } $RequestType = $_POST["RequestType"]; $ConsumerBusiness = $_POST["ConsumerBusiness"]; $GlobalLocation = $_POST["GlobalLocation"]; $FirstName = strtolower(str_replace("'","''",$_POST["FirstName"])); $FirstName = strtoupper(substr($FirstName,0,1)).substr($FirstName,1); $LastName = strtolower(str_replace("'","''",$_POST["LastName"])); $LastName = strtoupper(substr($LastName,0,1)).substr($LastName,1); $Email = strtolower(str_replace("'","''",$_POST["Email"])); $Title = strtolower(str_replace("'","''",$_POST["Title"])); $Title = strtoupper(substr($Title,0,1)).substr($Title,1); $Company = strtolower(str_replace("'","''",$_POST["Company"])); $Company = strtoupper(substr($Company,0,1)).substr($Company,1); $Address = strtolower(str_replace("'","''",$_POST["Address"])); $Address = strtoupper(substr($Address,0,1)).substr($Address,1); $City = strtolower(str_replace("'","''",$_POST["City"])); $City = strtoupper(substr($City,0,1)).substr($City,1); $State = $_POST["State"]; $Zip = $_POST["Zip"]; $Phone = $_POST["Phone"]; $F = $_POST["F"]; $ProductDesc = $_POST["ProductDesc"]; $Comment = $_POST["Comment"]; if ($GlobalLocation == "Canada"): $SendTo="canadainfo@------.com"; elseif ($GlobalLocation == "Central America"): $SendTo="customer.service@------.com.pa"; elseif ($GlobalLocation == "Europe"): $SendTo="marketing@-----.uk"; elseif ($GlobalLocation == "Mexico"): $SendTo="ventas@------.com.mx"; else: $SendTo="info@------.com"; endif; function dbSet($fields, $source = array()) { $set=''; if (!source) $source = &$_POST; foreach ($fields as $field) { if (isset($source[$field])) { $set.="`$field`='".mysql_real_escape_string($source[$field])."', "; } } return substr($set, 0, -2); } // INSERT INTO DATABASE mysql_select_db("new_contact",$dbc) or die("Could not select new_contact"); $fields = explode(" ", "RequestType ConsumerBusiness GlobalLocation FirstName LastName Email Title Company Address City State Zip Phone F ProductDesc Comment"); $query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST); mysql_query($query); // SETUP EMAIL $Bodycopy = "This information was submitted via the ------.com website and sent to you because of the location identified by the user. <br>If this has reached you in error, please forward this email to info@------.com"; $Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>"; if ($RequestType != "") $Bodycopy. "What kind of information do you need? : " .$RequestType. "<br>"; if ($ConsumerBusiness != "") $Bodycopy. "What type of customer or vendor are you? : " .$ConsumerBusiness. "<br>"; if ($GlobalLocation != "") $Bodycopy. "Global Location : " .$GlobalLocation. "<br>"; if ($Company != "") $Bodycopy. "Company : " .$Company. "<br>"; if ($FirstName != "") $Bodycopy. "First Name : " .$FirstName. "<br>"; if ($LastName != "") $Bodycopy. "Last Name : " .$LastName. "<br>"; if ($Title != "") $Bodycopy. "Title : " .$Title. "<br>"; if ($Email != "") $Bodycopy. "Email : " .$Email. "<br>"; if ($Address != "") $Bodycopy. "Address : " .$Address. "<br>"; if ($City != "") $Bodycopy. "City : " .$City. "<br>"; if ($State != "") $Bodycopy. "State : " .$State. "<br>"; if ($Zip != "") $Bodycopy. "Zip/Postal Code : " .$Zip. "<br>"; if ($Phone != "") $Bodycopy. "Phone : " .$Phone. "<br>"; if ($F != "") $Bodycopy. "F : " .$F. "<br>"; if ($ProductDesc != "") $Bodycopy. "UPC or product description : " .$ProductDesc. "<br>"; $Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>"; if ($Comment != "") $Bodycopy. "Comments : <br>" .$Comment. "<br>"; $Bodycopy. "<br><br>"; $Bodycopy. $IP = $_SERVER["remote_addr"]; // PROCESS EMAIL // mail server info... $from = $SendTo; $to = "Do Not Reply <donotreply@------>"; $subject = "Website Contact : " . $GlobalLocation; $body = $Bodycopy; $host = "mail.------"; $port = "25"; $username = "donotreply@-------"; $password = "-------"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'port' => $port, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } // MAKE SURE DB CONN IS CLOSED mysql_close($dbc); // REDIRECT TO THANK YOU PAGE header ('Location: /index.php?option'); exit(); } ?> So, i need this. |