Hi Guys, First im new here so hi everyone. Right, Ive got a select box which the user can select a figure, below that is another select box with yes and no. If they select no nothing happens if they select yes it takes 10% off the figure they selected when the submit button is clicked. When the button is clicked it sends me the answer. I've put the html and php code below, your prob laugh at it but im new to php so might be messy. <?php if(isset($_POST['submit'])) { $to = "myemailaddress"; $subject = "FORM"; $select1 = "select1"; $body = $select1 = if ($_POST['select2'] == 'yes') { $select1 *= 0.9; }; header("Location: index.php"); mail($to, $subject, $body); } else { echo ("Not Sent"); } ?> Code (markup): HTML: <select name="select1"> <option name="1000" value="1000">1000</option> <option name="2000" value="2000">2000</option> </select> <select name="select2"> <option name="selectbox">select box</option> <option name="yes" value="yes">yes</option> <option name="no" value="no">no</option> </select> <input type="submit" name="submit" value="Submit"/> Code (markup):
do you mean something like this? <?php if(isset($_POST['submit'])) { $to = "myemailaddress"; $subject = "FORM"; $select1 = $_POST['select1']; if ($_POST['select2'] == 'yes') { $select1 *= 0.9; mail($to, $subject, $select1); } else { echo ("Not Sent"); } ?> PHP: try this code, hope this is what you want. if you find any problems, do share here.
Tried the code and it didn't send the email, but you are correct thats exactly what im after, Any more ideas??? Thanks for the reply as well
well, it should work, are you trying on your localhost or where? try uploading this page on some online server to see whether it works or not. also try this code: <?php if(isset($_POST['submit'])) { $to = "myemailaddress"; $subject = "FORM"; $select1 = $_POST['select1']; if ($_POST['select2'] == 'yes') { $select1 *= 0.9; $message = stripslashes($select1); mail($to, $subject, $message); } else { echo ("Not Sent"); } ?> also make sure that you put in your email address in $to variable before sending the data.
Sorry dude my fault its working now If I select no though the email doesn't send - comes up with Not Sent would you do else { $select1 = $select1 } What I want is if you select no the figure to stays the same
oh ok, i thought you said you only wanted the yes thing. ok do like this <?php if(isset($_POST['submit'])) { $to = "myemailaddress"; $subject = "FORM"; $select1 = $_POST['select1']; if ($_POST['select2'] == 'yes') { $select1 *= 0.9; $message = stripslashes($select1); mail($to, $subject, $message); } elseif ($_POST['select2'] == 'no') { mail($to, $subject, $select1 ); } ?> PHP: try this. hope it works.
thanks dude, got that working now. I have one more thing and its complete. When no is selected and the submit button is clicked instead of it sending an email it just redirects to another page. how would you code this?
instead of elseif ($_POST['select2'] == 'no') { mail($to, $subject, $select1 ); } do this: elseif ($_POST['select2'] == 'no') { header("Location: your_desired_page.php"); }
ok so if the user selects no it will redirect to another page and wont send the email? say if i had 2 select boxes if the user selects over 3000 and in the next select box they choose yes then it works and the email is sent but if they select over 3000 and the user select no then it doesnt send the email and redirects. how would you code that one?? code: <select name="price"> <option name="1000">1000</option> <option name="2000">2000</option> <option name="3000">3000</option> <option name="4000">4000</option> <option name="5000">5000</option> </select> <select name="select"> <option name="yes">yes</option> <option name="no">no</option> </select>