PHP - Simple Form Help
Hello, I am trying to make a page with a text box in where the user enters their post code and hits 'Submit' then it loads a new page with an embeded google maps map of that area.
with the following code: <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=gym+**POSTCODE**&sll=37.0625,-95.677068&sspn=30.461748,86.572266&ie=UTF8&hq=gym&hnear=**POSTCODE**,+United+Kingdom&output=embed"></iframe><br /><small><a href="http://www.google.com/maps?f=q&source=embed&hl=en&geocode=&q=gym+**POSTCODE**&sll=37.0625,-95.677068&sspn=30.461748,86.572266&ie=UTF8&hq=gym&hnear=**POSTCODE**,+United+Kingdom" style="color:#0000FF;text-align:left">View Larger Map</a> I have typed **POSTCODE** where the user input needs to go.. Any ideas how this could be done? Thanks Similar TutorialsOn my website i have a form for customers to get in touch with me. This forum points to a php script to email me and tell them it has been submitted(via html). Here is the forum and the php script. Form from html file Code: [Select] <form id="supportform" name="Support Form" method="post" action="php/formemail.php"> <table width="100%" border="0"> <tr> <td width="22%">Name:</td> <td width="78%"><input type="text" name="name" id="name" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" /></td> </tr> <tr> <td>Company:</td> <td><input type="text" name="company" id="company" /></td> </tr> <tr> <td>Phone:</td> <td><input type="text" name="phone" id="phone" /></td> </tr> <tr> <td>Operating System:</td> <td><input type="text" name="os" id="os" /></td> </tr> <tr> <td>What Do You Need Help With?</td> <td><input type="text" name="problem" id="problem" /></td> </tr> <tr> <td>Additional Clarification:</td> <td><textarea name="additional" id="additional" cols="45" rows="3"></textarea></td> </tr> <tr> <td>Contact Preference:</td> <td><select name="preference" id="preference"> <option value="null">Please Select</option> <option value="phone">Phone</option> <option value="email">Email</option> </select></td> </tr> <tr> <td>How Did You Hear Of Us?</td> <td><select name="advert" id="advert"> <option value="null">Please Select</option> <option value="radio">Radio</option> <option value="newspaper">Newspaper</option> <option value="other">Other</option> </select></td> </tr> <tr> <td><input type="submit" name="Submit" id="submit" value="Submit" style="width:100px;height:30px" /> <input type="reset" name="reset" id="reset" value="Reset" style="width:62px;height:30px;" /></td> <td> </td> </tr> </table> </form> Here is php script Code: [Select] <?PHP /*Subject an email variables */ $emailSubject = 'PHP Email Script'; $webMaster = 'me@mysite;otherperson@gmail.com'; /* Gathering Data Variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $companyField = $_POST['company']; $phoneField = $_POST['phone']; $osField = $_POST['os']; $problemField = $_POST['problem']; $additionalField = $_POST['additional']; $preferenceField = $_POST['preference']; $advertField = $_POST['advert']; $body = <<<EOD <br><hr><br> Name: $nameField <br> Email: $emailField <br> Company: $companyField <br> Phone: $phoneField <br> OS: $osField <br> Problem: $problemField <br> Additional Info: $additionalField <br> Preference: $preferenceField <br> Advertising: $advertField <br> <br> Have a nice day! EOD; $headers = "From: $emailField\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Title</title> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" /> <link href="css.css" rel="stylesheet" type="text/css"> <style type="text/css"> body { background-color: #FFF; } </style> </head> <body> <div class="header"><a href="#"><img src="" alt="" name="greenhead" width="100%" height="17" id="greenhead" style="background: #B1FB17; display:block;" /></a> <!-- end .header --></div> <div class="content"> <h1> </h1> <h1><img src="/images/logo2.jpg" width="194" height="152" align="middle"> Tech Suppport MT</h1> <h1 align="center">Success!</h1> <h2 align="center">Your information has been submitted to us.</h2> <p align="center"> </p> <p align="center"><a href="/index.html">index - Home</a></p> <p> </p> <p> </p> <p> </p> </div> <div class="footer"> <h4 align="center">footer</h4> <!-- end .footer --></div> <!-- end .container --> </body> </html> EOD; echo "$theResults"; ?> Everything works as it should except both people are getting two emails. One email with everything correct and the correct results. And another with all null values from an unknown sender. I should not be receiving one from an unknown sender with empty values. Thanks for any help. Hello, I have just finished very simple contact form at http://stjohnsclaims.co.uk/test5/index-6.html and I am strugling to redirect the page to index.html, or any other URL when buttom "submit" is pressed. html file always reads contact.php file and then echo ("Your claim form was successfully sent!"); on blank background. How can I redirect it? I know this is very trivial question, but I have alrready spend many hours trying to fix it with no result. Thank you html body.... <div class="indent1"> <h2>Claim Form</h2> <form action="contact.php" method="get" id="form"><div class="container"> <div class="col-5"><h4>Your Details:</h4> <div class="h"><input name="name" type="text" class="input1" />Name:</div> <div class="h"><input name="surname"type="text" class="input1" />Surname:</div> <div class="h"><input name="tel"type="text" class="input1" />Tel:</div> <div class="h"><input name="email"type="text" class="input1" />Email Adress:</div> <div class="h"><input name="address"type="text" class="input1" />Address:</div> <div class="h"><input name="city"type="text" class="input1" />City:</div> <div class="h"><input name="postcode"type="text" class="input1" />Postcode:</div><p> <h4>Accident Details</h4> <div class="h"><input name="date"type="text" class="input1" />Date of Accident:</div> <div class="h"><input name="type"type="text" class="input1" />Accident Type:</div> </div> <div class="col-6">Accident details/Injuries sustained:</div> <div class="col-7"> <textarea name="message" class="textarea" rows="40" cols="30"></textarea> <div class="container1"> <div class="fright"> <a href="#" onclick="document.getElementById('form').reset()" class="link-1"><em><b>Clear</b></em></a> <div class="indent-2"> <a href="#" onclick="document.getElementById('form').submit()" class="link-1"><em><b>Submit</b></em></a></div> </div> </div> </div> </div></form> --------------------------------------------------------------- contact.php on the server <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']."\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("kc@kamil-cizek.com", $subject, " <html> <head> <title>Contact letter</title> </head> <body> <br> " . "name: " .$_GET['name']. "<br>" . "email: " .$_GET['surname']. "<br>" . "fax: " .$_GET['tel']. "<br>" . "age: " .$_GET['email']. "<br>" . "gender: " .$_GET['address']. "<br>" . "name: " .$_GET['city']. "<br>" . "email: " .$_GET['postcode']. "<p>" . "fax: " .$_GET['date']. "<br>" . "age: " .$_GET['type']. "<p>" . "message: <p>" .$_GET['message']." </body> </html>" , $headers); echo ("Your claim form was successfully sent!"); ?> I'm having trouble with this form. I can't seem to figure out the rest of what is required I have already done most of it...I'm just stuck on these parts: Province Select : (AutoGeneration, Multiple Select, Memory) AutoGeneration using Provinces Array: The Province Select box is generated by PHP using this array: provinces.txt Cut and paste this array into your own code. Multiple Selections: Note that the province select box permits multiple values to be selected. View the HTML source to see the configuration details. Also note how $_POST delivers these multiple values as an array. Select Box Memory: The Province select box retains the user choices after a POST. For each province selected by the user, your code will generate the "selected" attribute in the <options> tag for that province. View the HTML source of the working solution to see how this works. Status CheckBoxes (Multiple Select, Memory) Multiple Selections: Note that these checkboxes have been configured in the HTML to permit multiple selections. Also note that $_POST delivers these multiple selection values in an array. Status Box Memory:The Status Box retains the user choices after a POST. Your code will need to generate the "checked" attribute in the <input> tag for each item selected. Do not generate the checkboxes with an array. Location Radio button: Do not generate the radio buttons with an array. The Location radio button retains the user choice after a POST. Validation Success Message: Where does it go - The final success message is placed within the <div class="success"></div> tags at the top of the HTML. Use a Loop: Generate the success message with a single array loop that reads the $_POST array and prints out the success message as an ordered list. Form Variables List Un-Ordered List - The form variables are displayed in an unordered list . CSS removes the bullet. Names Capitolised - The names of the form variables are capitolised ( use strtoupper() function ) . Handle Empty Values - Print "---None supplied---" if the variable is empty. Province Long Names - Print the long names of the provinces selected as comma separated string Status Choices - Print the status choices as a comma separated string. Functions I need to use: empty() - is the string empty. Unfortunately, a "0" value counts as an empty string. strlen() - returns the number of characters in a string. is_numeric() - is the string a number count() - how many rows in an array is_array() - is the variable an array isset() - does the variable or member of array exist in_array() -does this string exist in this array strtoupper() - convert string to upper case. join() - you'll want this one too. Converts an array of strings into a string with a delimiter. error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); - suppresses warning messages in your code. Place at top. foreach ($_POST as $KEY => $VAL) {} - walk through the $_POST array (or any array) My code: Code: [Select] <!--"StAuth10065: I Adam Graham, 000136921 certify that this material is my original work. No other person's work has been used without due acknowledgement. I have not made my work available to anyone else."--> <? $PROVINCES = array( "--" => "--- Please Select Provinces ---", "nf"=>"Newfoundland", "pe"=>"Prince Edward Island", "nb"=>"New Brunswick", "ns"=>"Nova Scotia", "qc"=>"Quebec", "on"=>"Ontario", "mb"=>"Manitoba", "sk"=>"Saskatchewan", "ab"=>"Alberta", "bc"=>"British Columbia", "nt"=>"Northwest Territories"); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $dimwelcomeMsg = TRUE; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['uname'] == ''){ $errMsgs['uname'] = "Username must not be blank!!!"; $unameInError = true; } if (empty($_POST['year']) == TRUE){ $errMsgs['year'] = "Year must not be blank!!"; } if (count($errMsg) > 0 ): $dispErrorMsg = TRUE; else: foreach ($_POST as $key => $val): $key = strtoupper($key); $successMsg[$key] = $val; endforeach; $dispSuccessMsg = TRUE; endif; } ?> <html > <head> <title>Comp10065 - Simple Form Validatioon</title> <style type="text/css"> body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: green; } h2 { margin: 0px; padding: 10px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 200%; font-weight: normal; color: #FFF; background-color: #CCC; border-bottom: #BBB 2px solid; } h1 {color:#006600} p#copyright { margin: 20px 10px; font-size: 90%; color: #999; } div.form-container { margin: 10px; padding: 5px; background-color: #FFF; border: #EEE 1px solid; } p.legend { margin-bottom: 1em; } p.legend em { color: #C00; font-style: normal; } div.errors { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.errors p { margin: 0; } div.errors p em { color: #C00; font-style: normal; font-weight: bold; } div.success { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.success p { margin: 0; color:#006633} div.success li {list-style-type: none; } div.form-container form p { margin: 0; } div.form-container form p.note { margin-left: 170px; font-size: 90%; color: #333; } div.form-container form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; } div.form-container form legend { font-weight: bold; color: #666; } div.form-container form fieldset div { padding: 0.25em 0; } div.form-container label, div.form-container span.label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; } div.form-container label.error, div.form-container span.error { color: #000; } div.form-container select.error, div.form-container div.error {background-color: #FEF;} div.form-container label em, div.form-container span.label em { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; } div.form-container input.error { border-color: #C00; background-color: #FEF; } div.form-container input:focus, div.form-container input.error:focus, div.form-container textarea:focus { background-color: #FFC; border-color: #FC6; } div.form-container div.controlset {margin: 3px} div.form-container div.controlset label, div.form-container div.controlset input { display: inline; float: none; } div.form-container div.controlset div { margin-left: 170px; } div.form-container div.buttonrow { padding-left: 430px; border: 1px solid #CCCCCC } div#wrapper {width: 700px ; margin-left: auto; margin-right: auto} pre {color:black; font-size: 10pt; font-weight: bold; margin-left: 30px} </style> </head> <body> <div id="wrapper"> <h1> Form Validation Lab</h1> <div class="form-container"> <? if ($_SERVER['REQUEST_METHOD'] == 'GET') : ?> <? if (displayWelcomeMsg) : ?> <p>Please fill in the form........</p> <? endif; ?> <? endif; ?> <? if ($displaySuccessMsg): ?> <div class="success"> <p>Thank you for your submission.</p> <ol> <? foreach($successMsgs as $key => $successMsg): ?> <li><?= $key ?> = <?= $successMsg ?> </li> <? endforeach; ?> </ol> </div> <? endif; ?> <? if ($dispErrorMsg) : ?> <div class="errors"> <p><em>Oops...the following errors were encountered</em></p> <ul> <? foreach ($errMsgs as $key => $errMsg): ?> <li><?= $errMsgs ?> </li> <? endforeach; ?> </ul> <p>Please correct the errors and re-submit this form.</p> </div> <? endif; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="act" value="post"> <div class="buttonrow"> <input type="submit" value="Submit This Form " class="button" /> <a href="<?= $_SERVER['PHP_SELF'] ?>" >Start Again</a> </div> <p class="legend"><strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>)</p> <fieldset> <legend>User Details</legend> <div> <label for="uname" >User Name <em>*</em></label> <? if (isset($errMsgs['uname'])) echo 'class = "errors"' ?> <input id="uname" type="text" name="uname" value="<?=$_POST['uname'] ?>" /> (must be greater than 5 chars)</div> <div> <label for="email">Email Address </label> <input id="email" type="text" name="email" value="" /> </div> </fieldset> <fieldset> <legend>Submission</legend> <div> <label for="year">Year (YYYY) <em>*</em></label> <input id="year" type="text" name="year" <? if (isset($errMsgs['year'])) echo 'class = "errors"' ?> value="" size="4" maxlength="4" /> (4 digit number)</div> <div> <label for="date">Month (MM)</label> <input id="date" type="text" name="month" value="" size="4" maxlength="2" /> (number ranging from 1-12)</div> </fieldset> <fieldset> <legend>Preferences</legend> <div> <label for="type" >Province (Multiple Select) <em>*</em></label> <select name = "province[]" multiple size = "12" id="type" > <? foreach ($PROVINCES as $abbreviation => $longname); ?> <option value = "<?=$abbreviation ?> "></option> <? enfgoreach; ?> </select> </div> <div class= 'controlset' > <span class="label">Status (Mult Select)<em>*</em></span> <input name="status[]" id="approved" value="approved" type="checkbox" /> <label for="approved">Approved</label> <input name="status[]" id="pending" value="pending" type="checkbox" /> <label for="pending">Pending Application</label> <input name="status[]" id="actives" value="actives" type="checkbox" /> <label for="actives">Active Service</label> </div> <div class= 'controlset'> <span class="label"> Location <em>*</em></span> <input name="location" id="radio1" value="Garage" type="radio" /> <label for="radio1">Garage</label> <input name="location" id="radio2" value="Attic" type="radio" /> <label for="radio2">Attic</label> <input name="location" id="radio3" value="House" type="radio" /> <label for="radio3">House</label> </div> </fieldset> </form> <p>This debug info is here to help you. You are only required to display the POST array</p> <pre><?= print_r($_POST,true) ?> </pre> </div> </div> </body> </html> I want to have a form with a drop down menu that decides who gets the email. But I ALSO want the email to go to me. Can anyone tell me the simplest way to go about this? This is my form page: Code: [Select] <form method="post" action="sendorderform.php"> Email: <input name="email" type="text" /><br /> Message:<br /> <textarea name="message" rows="15" cols="40"> </textarea><br /> <select name='emailto' id='emailto'> <option value='me@yahoo.com'>man1@website.com</option> <option value='man2@website.com'>man2@website.com</option> <option value='man3@website.com'>man3@website.com</option> <option value='man4@website.com'>man4@website.com</option> </select><br> <input type="submit" /> </form> This is my php page: Code: [Select] <?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $email_to = $_POST['emailto'] ; mail( $email_to, "Feedback Form Results", $message, "From: $email" ); ?> I actually got this to send per the drop down. But, where do I put MY (fixed) email address to make it send TWO emails? Thanks for any help!!! I'm very new at this stuff. I am trying to add some simple validation to my form. I only wanter users to be able to enter 11 numbers into the number field or else it will say 11 digit numbers only. A validation to only allow users to input numbers anything else and it brings up an error. and finally i want to check the email string to make sure it has an @ and a (.) . How would i go about adding these validation techniques to this code? <?php if ($_SERVER['REQUEST_METHOD']=="POST"){ // Recipent Email $to="andrew@peppermintdigital.com"; $subject="Reply to Peppermint Invitation"; $title = $_POST['title']; $name = stripslashes($_POST['name']); $add1 = stripslashes($_POST['add1']); $add2 = stripslashes($_POST['add2']); $add3 = stripslashes($_POST['add3']); $add4 = stripslashes($_POST['add4']); $postcode = stripslashes($_POST['postcode']); $number = stripslashes($_POST['number']); $email = stripslashes($_POST['email']); $time = $_POST['time']; $from = ($_POST['name']) . "<".stripslashes($_POST['email']).">"; $subject = ($_POST['name']) . "<".stripslashes($_POST['email']).">"; // Email Message $message = "Name : $title $name. Address : $add1, $add2, $add3, $add4, $postcode. Phone Number : $number. Email : $email. Appointment Time : $time"; // Validation Begins // Add Erros To Array $errors = array(); // Check Form if (!$_POST['title']) $errors[] = "Title Required"; if (!$_POST['name']) $errors[] = "Name Required"; if (!$_POST['add1']) $errors[] = "Address Required"; if (!$_POST['add4']) $errors[] = "City Required"; if (!$_POST['postcode']) $errors[] = "Postcode Required"; if (!$_POST['number']) $errors[] = "Number Required"; if(!$_POST['number'] == 11) $errors[] = "Full Number Required"; if (!$_POST['email']) $errors[] = "Email Required"; if (!$_POST['time']) $errors[] = "Time Required"; // Display Errors if (count($errors)>0) { echo"<h1 class='fail'>"; foreach($errors as $err) echo "$err.\n"; echo"</h1>"; echo " <form method='post' action='#'> <table cellpadding='0' cellspacing='0' border='0'> <tr> <td class='form_results' colspan='2'> </td> </tr> <tr> <td class='form_left' valign='top'> <table width='200' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='title_left' valign='top'>Title</td> </tr> <tr> <td class='sname_left' valign='top'>Name</td> </tr> <tr> <td class='add_left' valign='top'>Address</td> </tr> <tr> <td class='post_left' valign='top'>Postcode</td> </tr> <tr> <td class='number_left' valign='top'>Phone Number</td> </tr> <tr> <td class='email_left' valign='top'>Email Address</td> </tr> <tr> <td class='time_left' valign='top'>Appointment Time</td> </tr> </table> </td> <td class='form_right' valign='top'> <table width='300' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='right_spacer'> <select name='title' class='select'> <option>Mr</option> <option>Mrs</option> <option>Ms</option> <option>Miss</option> </select> </td> </tr> <tr> <td class='right_spacer'><input type='text' name='name' class='field' value='$name' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add1' class='field' value='$add1' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add2' class='field' value='$add2' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add3' class='field' value='$add3' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add4' class='field' value='$add4' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='postcode' class='field' value='$postcode' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='number' class='field' value='$number' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='email' class='field' value='$email' /></td> </tr> <tr> <td class='right_spacer'> <select name='time' class='select'> <option>5.30 pm</option> <option>6.30 pm</option> <option>7.30 pm</option> </select> </td> </tr> </table> </td> </tr> <tr> <td class='form_buttom' colspan='2'> <input name='submit' type='submit' value='Submit' class='submit_button' /> </td> </tr> </table> </form> "; } else { // Build message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // Send message if (@mail($to, $subject, $message, $headers)) echo "<h1 class='success'>Your message has been sent.</h1>"; else echo "<h1 class='fail'>Your message was not sent at this time.</h1>"; } } else { echo " <form method='post' action='#'> <table cellpadding='0' cellspacing='0' border='0'> <tr> <td class='form_results' colspan='2'> </td> </tr> <tr> <td class='form_left' valign='top'> <table width='200' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='title_left' valign='top'>Title</td> </tr> <tr> <td class='sname_left' valign='top'>Name</td> </tr> <tr> <td class='add_left' valign='top'>Address</td> </tr> <tr> <td class='post_left' valign='top'>Postcode</td> </tr> <tr> <td class='number_left' valign='top'>Phone Number</td> </tr> <tr> <td class='email_left' valign='top'>Email Address</td> </tr> <tr> <td class='time_left' valign='top'>Appointment Time</td> </tr> </table> </td> <td class='form_right' valign='top'> <table width='300' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='right_spacer'> <select name='title' class='select'> <option>Mr</option> <option>Mrs</option> <option>Ms</option> <option>Miss</option> </select> </td> </tr> <tr> <td class='right_spacer'><input type='text' name='name' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add1' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add2' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add3' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='add4' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='postcode' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='number' class='field' /></td> </tr> <tr> <td class='right_spacer'><input type='text' name='email' class='field' /></td> </tr> <tr> <td class='right_spacer'> <select name='time' class='select'> <option>5.30 pm</option> <option>6.30 pm</option> <option>7.30 pm</option> </select> </td> </tr> </table> </td> </tr> <tr> <td class='form_buttom' colspan='2'> <input name='submit' type='submit' value='Submit' class='submit_button' /> </td> </tr> </table> </form> "; } ?> Hi, I have a php form that I use to try to get matching data from the database that I put into the form. So if I enter date of birth 9-4-80 and first name Dave and lastname Smith. When I submit it the code should pull all of the matching terms out of the database and display. Now I get the following error when I submit the form. Query: Resource id #2 Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1 any help Greatly appreciated. thank you! here is the code Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = " "; $database = " "; $username = " "; $password = " "; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //include('bouncer.php'); //$currentUser = $_SESSION['myusername']; if(isset($_POST['submit'])) { $first = mysql_real_escape_string( $_POST['first']); $last = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); //THE SEARCH FUNCTION $sql = mysql_query ( "SELECT * FROM users WHERE firstname LIKE '%$first%' OR lastname LIKE '%$last%' OR dob LIKE '%$dob%' ") or die(mysql_error()); $result = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["firstname"]; echo $row["lastname"]; echo $row["dob"]; } }//if(isset($_POST['submit'])) ?> <html> <body> <form action="login_success8.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="submit" name="submit" value="Search" /> <input type="reset" value="Reset fields" /> </p> </form> </body> </html> hi iam trying to make a simple search form to search the members tables based on there input. iam new php so most of my code is guess work Code: [Select] <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> <label for="country">Country:</label> <input type="text" name="country" /> <label for="state">State:</label> <input type="text" name="state" /> <label for="city">City:</label> <input type="text" name="city" /> <input type="submit" value="submit" /> </form> <? if ($_GET == array ()) { //Define a variable that will be used to query the members; in this case, it would select all members $query = "SELECT * FROM users"; } else { //If the user typed at least one thing (in the form OR the url) if (count ($_GET) == 1) { //If what they typed is only for one criteria, define a variable that creates a query for only ONE criteria to search for $query = "SELECT * FROM users WHERE 1"; foreach ($_GET as $field => $value) { $query .= " AND $field = '$value'"; } //If the user has typed in more than one field and hits search } else { //Define a variable for a query that selects members based off each criteria $query = "SELECT * FROM users WHERE 1"; foreach ($_GET as $field => $value) { $query .= " AND $field LIKE '%$value%'"; } } while($info = mysql_fetch_array( $data )) { Echo "<img src='http://datenight.netne.net/images/".$info['img'] ."' width='150' height='250''> <br>"; Echo "<b>Name:</b> ".$info['username'] . "<br> <hr>"; Echo "<b>Sex:</b> ".$info['sex'] . " <br><hr>"; Echo "<b>Intrested in</b>" . "<br><hr>"; Echo "".$info['rel'] . " "; Echo "".$info['frwb'] . " "; Echo "".$info['ons'] . " "; Echo "".$info['fr'] . "<br><hr>"; Echo "<b>About me:</b> ".$info['aboutme'] . "<br><hr> "; Echo "<b>Looking for:</b> ".$info['looking'] . " <br><hr>"; Echo "<a href='login_success.php'>'Back'</a>"; } ?> </body> </html> while($info = mysql_fetch_array( $data )) { is not vaild error Hi, I am new to php, and I have run into a problem. The tutorial I am using has provided me with this exact code. But it does not work for me. Its very simple. Here is the HTML page: Code: [Select] <body> <FORM ACTION="welcome.php" METHOD=POST> First Name: <INPUT TYPE=TEXT NAME="name"> <INPUT TYPE=SUBMIT VALUE="GO"> </FORM> </body> And here is the php page: <body> <?php echo( "Welcome to our Web site, $name!" ); ?> </body> You can see the problem live at <http://www.freewaycreative.com/test> (dont mind the digits below) The name just does not show. Anyone know why? Thanks! Hello, I am trying to use this contact form that emails out. however it wants to be placed beside the file that uses it. However i would need a bunch of these files than for what i am trying to do. I want it to be set up like this. website root | | scripts | scriptfile right now its like this website root | | about | | contact | | script file here is the from data in my webpage <form action="FormToEmail.php" method="post"> <table border="0" style="background:#ececec" cellspacing="5"> <tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr> <tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> <tr align="left"><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> <tr align="left"><td> </td><td><input type="submit" value="Send"></td></tr> </table> </form> here is the script data <?php error_reporting(E_ALL ^ E_NOTICE); $my_email = "test@test.com.com"; $from_email = ""; /* Optional. Enter the continue link to offer the user after the form is sent. If you do not change this, your visitor will be given a continue link to your homepage. If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm" */ $continue = "/"; /* Step 3: Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace. IMPORTANT - The file name is case sensitive! You must save it exactly as it is named above! THAT'S IT, FINISHED! You do not need to make any changes below this line. */ $errors = array(); // Remove $_COOKIE elements from $_REQUEST. if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} // Validate email field. if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } // Check referrer is from same site. if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} // Check for a blank form. function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); // Display any errors and exit if errors exist. if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} // Build message. function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");} $message = build_message($_REQUEST); $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.""; $message = stripslashes($message); $subject = "Doctor Dave Question"; $subject = stripslashes($subject); if($from_email) { $headers = "From: " . $from_email; $headers .= PHP_EOL; $headers .= "Reply-To: " . $_REQUEST['email']; } else { $from_name = ""; if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);} $headers = "From: {$from_name} <{$_REQUEST['email']}>"; } mail($my_email,$subject,$message,$headers); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form To Email PHP script from FormToEmail.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#ffffff" text="#000000"> <div> <center> <b>Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b> <br>Your message has been sent <p><a href="<?php print $continue; ?>">Click here to continue</a></p> </center> </div> </body> </html> thank you. on a side note the text box wher ei entered this in is anoyying. it jumps and bounces every letter i type. Hi! I am not great at using php but do use it to process forms on websites. I always use the same script and just change the relevant sections for each website. This usually works with no problems. I am writing an mailing list subscribe/unsubscribe form my website and it works fine as in I get the email sent through with all the information on it and the automated reply gets sent out etc. The problem is that once the user hits Submit instead of going to the redirect page it stays on the php page. if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.hillsideweb.co.uk/unsubthanks.html" );} Like I say this exact script works on another site of mine perfectly well, can someone please help me solve this. The form is found on http://www.hillsideweb.co.uk/unsubscribe.html I hope this makes sense! Many thanks Swenglish Ok so I already have a "post" action URL, here it is below. <form method="post" action="http://survey.leisuretrends.com/RemoteSurvey.asp?survey=321&survey_version=1330"> The idea is to put a simple e-mail form on my personal website: And have the post action to go to the URL above (its a marketing company for email submissions / newsletters) Here is what I have so far, but I know something is not right: Quote <form> <input type="text" /> <input type="submit" /> <form method="post" /> <form action="http://survey.leisuretrends.com/RemoteSurvey.asp?survey=321&survey_version=1330"/> </form> Any help would be greatly appreciated. Thank you for your patience with me Hi, Today I have taken my first step towards familiarisation with php. I have created a simple form form a tutorial I read. The mail.php file is this: Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "fathernugen@googlemail.com"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "You have been added to our newsletter subscription list!" . " -" . "<a href='newsletter.php' style='margin:0 auto; top: 100px; text-decoration:none;color:#ff0099;'> Return to Sitting Spiritually</a>"; ?> My problem is that users are redirected to a blank page with 'thank you return to sitting spiritually'. I would like to use a custom thank you page with a url like; www.sittingspiritually.co.uk/thankyou.php so the look of the site is not completely ruined by my php inadequacies. Is there a small piece of code i can add to the mail.php file so i can use a custom page for the success??? I hope some one can help, thanks in advance. Hi guys I'm trying to modify the following script so that only registered users can post comments. Can you guys help please thanks? <?php require_once("admin_common.php"); session_start(); if(is_numeric($_REQUEST['id'])){ $imageid = $_REQUEST['id']; }else{ header("Location: http://mysite.net/"); } if($_POST['submit']){ if($_POST['username']==''){ $err = "You must log in."; }elseif($_POST['thecomment']==''){ $err = "You have to enter a comment."; }else{ $name = strip_tags($_POST['thename']); $themessage = strip_tags($_POST['thecomment']); $ezdb->get_results("INSERT INTO user_comments (id,date_added, posted_by, message, image_id) VALUE ('','".time()."','".$name."','".$themessage."','".$imageid."')"); $err = "Thank you for your comment."; } } if($err){ $err = '<span style="color:#FF0000;">'.$err.'</span>'; } /* Update table `iid_ip`. Between the dashed lines is the create statement used to create the image view count (iid_ip) table. ---------------------------------------- delimiter $$ CREATE TABLE `iid_ip` ( `iid` int(11) unsigned NOT NULL COMMENT 'Image id from where the count is the number of unique views.', `ip` varchar(15) NOT NULL COMMENT 'The ip of the visitor.', PRIMARY KEY (`iid`), KEY `ip` (`ip`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Table for view count of image using unique ip''s.'$$ ---------------------------------------- */// Escape variables that are used in the query. $_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $_iid = mysql_real_escape_string($imageid); // Count is 0 if ip has NOT seen the images, else count is 1 $_count = $ezdb->get_var("SELECT COUNT(*) FROM `iid_ip` WHERE `iid`='$_iid' AND `ip`='$_ip'"); if (!$_count) { // Insert the unique combination of image id and visitor ip in `iid_ip`. // Method doesn't exists! $ezdb->quick_insert('iid_ip', array('iid' => $_iid, 'ip' => $_ip)); $ezdb->get_results("INSERT INTO `iid_ip` (`iid`,`ip`) VALUES ('$_iid','$_ip')"); } // Get count of image views. $_views = $ezdb->get_var("SELECT COUNT(*) FROM `iid_ip` WHERE `iid`='$_iid'"); // And format, thousands seperator is a comma, no decimals. $_views = number_format($_views, 0, '', ','); ///////////////////////////// $page->addHTMLHead($scripthead); $d[] = "<div id='imagedetails'>"; $imgs = $ezdb->get_results("Select * From image_map Where id='".$imageid."'"); $name = $ezdb->get_var("Select name From `".$imgs[0]->obj_type."s` WHERE id ='".$imgs[0]->obj_id."'"); if($imgs[0]->obj_type=='comment') $pg='comm'; if($imgs[0]->obj_type=='image') $pg='img'; $d[] = "<a href='imagepage.php?".$pg."=".$imgs[0]->obj_id."' style='text-decoration:none;'>«".ucfirst($imgs[0]->obj_type)."s - $name</a><br /><br />"; // DEFINE SIMPLE GRID if ($imgs[0]->user_id != 0) { $theuser = $ezdb->get_var("SELECT username FROM users WHERE user_id='".$imgs[0]->user_id."'"); } else { $theuser = $imgs[0]->creator_name; } $d[]="<div style='float:left; width:450px; text-align:center;'> <a href='contact.php'><img src='assets/images/leftAdjpg'></a> <br /> <div style='font-size:12px; margin-top:30px; margin-left:5px;'> ".'Html Code: Use for websites, blogs, profiles and myspace.<br /><input name="textfield3" type="text" class="imagedetails_links" id="textfield3" onclick="this.select();this.focus()" value="<a href="http://www.mysite.net/imagedetails.php?id='.$imageid.'"><img src="http://www.mysite.net/uploads/'.$imgs[0]->link.'" border="0" alt=" " /></a><br /><a href="http://www.mysite.net"></a>" size="70" /> <br /> For posting in forums use this: <input name="textfield6" type="text" class="imagedetails_links" id="textfield6" onclick="this.select();this.focus()" value="[url=http://www.mysite.net][img]http://www.mysite.net/uploads/'.$imgs[0]->link.'[/img][/url]" size="70" /> <br /> </div> <div style="float:left; width:450px; margin-left:34px; margin-top:5px;"><table width="100" border="0"> <tr> <td class="widgets"><a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></td> <td class="widgets"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fmysite.net%2F&layout=box_count&show_faces=false&width=450&action=like&font=arial&colorscheme=light&height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:65px;" allowTransparency="true"></iframe></td> </tr> </table></div> '; if(ereg('.gif',$imgs[0]->link)){ $thelarge ="<img src='uploads/".$imgs[0]->link."' alt='".$imgs[0]->name."' style='border:0px solid #cccccc;' />"; }else{ $thelarge ="<img src='imageresize.php?imagepath=uploads/".$imgs[0]->link."&width=500&height=500' alt='".$imgs[0]->name."' style='border:0px solid #cccccc;' />"; } $d[]=" </div> <div style='float:left; margin-left:10px;'> <p style='padding:0; margin:0; margin-right:20px; text-align:center; font-size:14px;'><a href='force.php?path=uploads/".$imgs[0]->link."'>Click to Download Image</a></p><br /> ".$thelarge." <div style='overflow:auto; clear:both'> <div style='float:left; text-align: left;'> Image: <span style='color:#FFFFFF;'>{$imgs[0]->name}</span><br /> <span style='color:#ffffff; font-size:13px;'>Posted on: ".date('m-d-Y',$imgs[0]->date_added)." by ".ucfirst($theuser)."</span> </div> <div style='float:right'> <!-- Insert unique view count --> <span style='color:#ffffff; font-size:13px;'>Views: $_views</span> </div> </div> ".' </div> <div style="clear:both;"></div> <div style="margin:0 auto;"><br />'.$err.' <form action="'.$_SERVER['PHP_SELF'].'" method="post" style="margin:0 auto; width:400px; color:#ffffff; font-size:11px; text-align:left;"> <div style="margin-bottom:5px;">Leave a comment:</div><input type="hidden" name="id" value="'.$imageid.'" /> Your name: <input type="text" name="thename" style="width:250px;" class="inputfields" value="'.$_SESSION['username'].'"/><br /> Your comment:<br /><textarea name="thecomment" style="width:400px; height:70px;" cols="50" rows="4" class="textareas" ></textarea><br /> <input type="submit" name="submit" value="Post Comment" style="float:right;"/> </form> </div>'; $getallcomments = $ezdb->get_results("SELECT * FROM user_comments WHERE image_id='".$imageid."' ORDER BY date_added DESC"); $uclist = '<div style="margin:0 auto; width:410px; padding:5px; border:0px solid #cccccc; margin-top:40px;">'; if(sizeof($getallcomments)>0){ foreach ($getallcomments as $ac){ $uclist .='<div style="border-bottom:2px solid #333333; width:400px; color:#ffffff; font-size:12px; margin:0 auto; text-align:left;"><br />Posted on:<span style="color:#000000;"> '.date('m-d-Y',$ac->date_added).' at '.date('H:i a',$ac->date_added).'.</span><br />Posted by:<span style="color:#000000;"> '.strip_tags($ac->posted_by).'</span><br /><span style="color:#ffffff;">'.strip_tags($ac->message).'</span></div>'; } }else{ $uclist.='<div style="border-bottom:2px solid #ffffff; width:400px; color:#ffffff; font-size:12px; margin:0 auto; text-align:center;">Be the first to leave a comment!</div>'; } $uclist.="</div><div style='clear:both;'></div><br /><br />"; $d[] = $uclist."</div>"; $page->add($d); echo $page->render(); ?> I have an error somewhere in the form as it does not output what I want it too. I know the form itself is working as I have added an echo to see if the form inputs are processed. the code: Code: [Select] <?php $amount = $_POST['amount']; $member = $_POST['member']; $sql = ("SELECT name FROM vtp_members WHERE name=".$member." "); $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows = '1') { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "You sent ". $amount . " to " . $member . ".<br />"; } } echo " ".$amount." and ".$member." "; ?> It outputs the last echo correct. is there anyone who can see what I'm doing wrong? so, I've been trying to build a contact form for about a week now. straight. no kidding. I'm entirely new to php and basically know nothing more than i can assume based on other scripting/coding experience. I know there's probably answers to similar questions all over the place, but I've been trying literally hundreds of different pre-built forms guaranteed to work and solutions to others' problems, etc etc and not a single one has operated correctly for me. I can't really do anything with a "you should try this/that approach" answer, nor can I be assumed to know anything about php; I pretty much just need someone to fix whatever the problem is and paste it back to me as this is the only thing keeping me from launching the site. this is what prints when trying to submit with the dropdown on the default value: Quote Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\5810110\html\contact\contact.php on line 32 There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]. this prints when any item other than the default is selected in the dropdown: Quote Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\5810110\html\contact\contact.php on line 32 Warning: mail() [function.mail]: SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in D:\Hosting\5810110\html\contact\contact.php on line 33 There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]. http://email.about.com/cs/standards/a/smtp_error_code_2.htm specifically states to ignore both these errors, yet http://cr.yp.to/docs/smtplf.html specifically states that it's a fault of mine. here's the html: Code: [Select] <div id="formHolder"> <form method="post" action="contact.php"> <table class="contactTable" align="center"> <tr> <td> Subject: </td> <td> <select name="sendto"> <option value="bs from N1K.com">General Inquiry</option> <option value="JOB OFFER">Design Contract</option> <option value="PURCHASE ORDER">Purchase Order/Offer</option> </select> </td> </tr> <tr> <td><font color=red>*</font>Name:</td> <td><input size=25 name="Name"></td> </tr> <tr> <td><font color=red>*</font>Email:</td> <td><input size=25 name="Email"></td> </tr> <tr> <td>Company:</td> <td><input size=25 name="Company"></td> </tr> <tr> <td>Phone:</td> <td><input size=25 name="Phone"></td> </tr> <tr> <td>Subscribe to<br> mailing list: </td> <td><input type="radio" name="list" value="No"> Pf, nothx.<br> <input type="radio" name="list" value="Yes" checked> H3X Y34!<br> </td> </tr> <tr> <td colspan=2>Message:</td> </tr> <tr> <td colspan=2 align=center> <textarea name="Message" rows=5 cols=35></textarea> </td> </tr> <tr> <td colspan=2 align=center> <input type=submit name="send" value="Submit"> </td> </tr> </table> </form> </div><!-- END formHolder --> and here's the php: <?php $to = "god@neurot1k.com" ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = $_REQUEST['sendto'] ; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"list"} = "Mailing List"; $fields{"Message"} = "Message"; $body = "I have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: god@neurot1k.com"; $subject2 = "autoconfirm from neurot1k.com"; $autoreply = "Thanks for the contact, I'll get back to you as soon as possible, usually within 48 hours. If you have any more questions, please try me on AIM: ycleptCrux"; if($from == '') { print "You have not entered an email, please go back and try again"; } else { if($name == '') { print "You have not entered a name, please go back and try again"; } else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { print "Thanks, I'll get back to you as soon as possible."; } else { print "There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]."; } } } ?> the form was copy/pasted from http://php.about.com/od/phpapplications/ss/form_mail.htm and then respective variables were changed (email address, dropdown fields, etc). I didn't think it'd be SUCH a problem to copy/paste a pre-written block of code from About.com... HUGE thanks in advance to anyone willing to helo. Hey everyone. I hope you can help me getting through this problem, because I have no idea of what else to try. I'm a web designer and sometimes modify Javascript, but my main focus is HTML and CSS, meaning I have no idea how to code in Javascript, but most importantly, how to write something from scratch in PHP. So I designed a form that works pretty well, and integrated a PHP and Javascript script to make it work. This is the form: Code: [Select] <form name="form" id="form" method="post" action="contact.php"> <p>Hello,</p> <p>My name is <input type="text" name="name">, from <input type="text" name="location">, and I'd like to get in touch with you for the following purpose:</p> <p><textarea name="message" rows="10" ></textarea></p> <p>By the way, my email address is <input type="text" name="email" id="email" placeholder="john@doe.com">, and I can prove I'm not a robot because I know the sky is <input type="text" name="code" placeholder="Red, green or blue?">.</p> <p title="Send this message."><input type="submit" id="submit" value="Take care."></p> </form> And this is the script, in an external file called contact.php: Code: [Select] <?php $name = check_input($_REQUEST['name'], "Please enter your name.") ; $location = check_input($_REQUEST['location']) ; $message = check_input($_REQUEST['message'], "Please write a message.") ; $email = check_input($_REQUEST['email'], "Please enter a valid email address.") ; if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {die("E-mail address not valid");} if (strtolower($_POST['code']) != 'blue') {die('You are definitely a robot.');} $mail_status = mail( "my@email.com", "Hey!", "Hello,\n\n$message\n\nRegards,\n\n$name\n$location", "From: $email $name" ); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for the message. I will try to respond as soon as I can.'); window.location = '/about'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('There was an error. Please try again in a few minutes, or send the message directly to aalejandro@bitsland.com.'); window.location = '/about'; </script> <?php } ?> So what it does is this: if everything's OK, it sends an email with "Hey!" as the subject, "[name]" as the sender, "Hello, [message]. Regards, [name], [location]" as the body, and a popup saying the message was delivered appears. If something fails, it outputs the error in a new address, so the user will have to go back to the form and correct the error. What I actually want to happen is this: if everything's OK, a <p> which was hidden beneath the form appears saying the message was delivered, or, alternatively, make the submit button gray out and confirm the message was delivered. I found a script to make this happen, but with "Please wait...", so the user can't resubmit the form. If there's an error, I'd like another <p> which was hidden to appear with the specific error, so there'd be many <p>'s hidden with different IDs. If possible, I'd also like to change the CSS style of the input field, specifically changing the border color to red, so it'd be a change in class for the particular field. -- So in essence, I want the errors and the success messages to output in the same page as the form (without refresh), and a change of class in the input fields that have an error. Thanks in advance, and please let me know if it'll be possible. Alright so I am trying to code a very simple form that adds a user to my SQL database with certain information filled in and certain information kept hidden with default values in a form. My index.php file is as follows (not all of the code but just the form part): <?PHP $submitMessage = $_GET['value']; if ($submitMessage == success) { echo '<div class="congratulations"><font color="#84d20c"><strong>Congratulations:</strong></font> The user has been added.</div>'; }else if($submitMessage == NULL){ }else if($submitMessage == fail){ echo '<div class="error"><font color="#d3430c"><strong>Error:</strong></font> An error occurred please check the error details below:</div>'; echo 'ERROR DETAILS:'; echo mysql_error(); } ?> <h1><i>Add User</i></h1> <p>This page is where you would manually add a user to the donations databases (for example you or a member of the community with elevated status that does not need to pay).</p> <br/> <form enctype="multipart/form-data" action="scripts/admin_save_sm_db.php" method="post"> <input name="authtype" value="steam"/><br /><br /> <h3><i>STEAM ID:</i></h3> <input name="identity" value="STEAM_0:X:XXXXXXXX"/><br /> <div class="form_help">Steam ID of the player you wish to add. Must be in the format STEAM_0:X:XXXXXXXX</div><br /> <input name="flags" value="o"/><br /><br /> <input name="name" value="Donator"/><br /><br /> <input name="immunity" value="0"/><br /><br /> <h3><i>Your Email Address</i></h3> <input name="user_email"/><br /> <div class="form_help">Your Email Address for security purposes.</div><br /> <input name="Submit" type="submit" value="Submit" class="form_submit" /> </form> My admin_save_sm_db.php file is as follows: <?php session_start(); if(!isset($_SESSION["username"])) { header('Location: login.php'); exit; } @require("../sm_admin_db.php"); $authtype = $_POST['authtype']; $identity = $_POST['identity']; $flags = $_POST['flags']; $name = $_POST['name']; $immunity = $_POST['immunity']; $user_email = $_POST['user_email']; $link = @mysql_connect(_HOST,_USER,_PASS); @mysql_select_db(_DB); $sql = @mysql_db_query(_DB,"INSERT INTO "._TBL." (`authtype`, `identity`, `flags`, `name`, `immunity`, `user_email`) VALUES (NULL, '$authtype', '$identity', '$flags', '$name', '$immunity', '$user_email')"); $okay = @mysql_affected_rows(); if($okay > 0) { header( "Location: ../index.php?value=success" ); } else { header( "Location: ../index.php?value=fail" ); } @mysql_close($link); ?> And finally my sm_admin_db.php file is as follows: <?PHP //host loaction define("_HOST", "localhost", TRUE); //database username define("_USER", "thatsact_admin", TRUE); //database username`s password define("_PASS", "*********", TRUE); //database name define("_DB", "thatsact_sadadmins", TRUE); //database table name change this to install multiple version on same database define("_TBL", "sm_admins", TRUE); //This is the email that you will recieve emails when someone signs up. define("_EMAIL", "admin@tag-clan.com", TRUE); ?> All of this together does not work and gives the echo error code, however the mysql_error() string does not return anything. Nothing is inserted into the database. Can I get some help on where I went wrong and please keep in mind I am VERY new to php and didn't write most of this script so just tell me what to edit and exactly how to do it please. Thanks in advance. Hi I'm trying to set up my first contact form, but I keep getting this error message:
Parse error: syntax error, unexpected end of file in /home/remem539/public_html/php/testform.php on line 85
here's my code, what am I doing wrong?
<?php
if ($_POST['parse_var'] == "testform"){ Helo - Total newbie here, so please keep that in mind. I'd really appreciate some wisdom from someone here as to how you would improve this form: <?php $email = $_POST['email']; $message = $_REQUEST['message']; $message = $_POST['date']; $message .= $_POST['location']; $message .= $_POST ['comments']; mail( "testing@gmail.com, 5602346789@metropcs.com", "General Inquiry", $message, "From: $email" ); header( "Location: thankyou.html" ); ?> *******************************html****************************** <HEAD><title>Hi</title<HEAD><BODY BGCOLOR="lightgray"><br><br><center><br><br><form method="post" action="sendmail2.php"><table cellspacing="5" cellpadding="5" border="0"> <tr> <td valign="top"><font face="arial"> <strong>Contact email:</strong><br> </td> <td valign="top"><font face="arial"> <input type="text" name="email" size="50" value="" /> </td> </tr><tr><td valign="top"><font face="arial"> <strong>Date:</strong> </td> <td valign="top"><font face="arial"> <input type="text" name="date" size="50" value="" /> </td> </tr> <tr><td valign="top"><font face="arial"> <strong>location:</strong><br> </td> <td valign="top"> <input type="text" name="location" size="50" value="" /> </td> </tr> <tr> <td valign="top"><font face="arial"> <strong>Comments:</strong><br><font color="black"> </td> <td valign="top"> <textarea name="comments" rows="6" cols="40"></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </table> </form></center></body> |