Email submission form with maths

Discussion in 'PHP' started by apg1985, Jan 16, 2009.

  1. #1
    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):
     
    apg1985, Jan 16, 2009 IP
  2. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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.
     
    khan11, Jan 16, 2009 IP
  3. apg1985

    apg1985 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    apg1985, Jan 16, 2009 IP
  4. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #4
    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.
     
    khan11, Jan 16, 2009 IP
  5. apg1985

    apg1985 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry dude my fault its working now :D

    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
     
    apg1985, Jan 16, 2009 IP
  6. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #6
    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.
     
    khan11, Jan 16, 2009 IP
  7. apg1985

    apg1985 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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?
     
    apg1985, Jan 18, 2009 IP
  8. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #8
    instead of
    elseif ($_POST['select2'] == 'no') {
    mail($to, $subject, $select1 );
    }

    do this:

    elseif ($_POST['select2'] == 'no') {
    header("Location: your_desired_page.php");
    }
     
    khan11, Jan 18, 2009 IP
  9. apg1985

    apg1985 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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>
     
    apg1985, Jan 18, 2009 IP
  10. apg1985

    apg1985 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    another question ive got is how would I round up the number being sent to my email address???
     
    apg1985, Jan 19, 2009 IP