Simple php equals question

Discussion in 'PHP' started by Silver89, Nov 3, 2006.

  1. #1
    Ok, its late at night and my brains playing tricks on me.

    <input type="text" class="form1" id="emailaddress" name="emailaddress">

    Is the input for the email address,

    this is then got within the php with

    $_POST["emailaddress"]

    I then want to have this equaled here

    $sFromEmailName = "$emailaddress";

    Whats wrong with that??

    Thanks
     
    Silver89, Nov 3, 2006 IP
  2. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are trying to assign the value of the field emailaddress from the post to the sFromEmailname variable, then you would want this:
    $sFromEmailName = $_POST['emailaddress'];
    PHP:
     
    tflight, Nov 3, 2006 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    ok, thanks

    however i have realised that when the first part of the form is submit the fields are blank so nothing is being sent in the second part,

    so i need to save

    $_POST['emailaddress']

    into a cookie but only if post is full and then have

    $sFromEmailName =

    equal the content of that cookie
     
    Silver89, Nov 3, 2006 IP
  4. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't think that's necessary (cookies). Check your form fields and also validate the input with javascript or php. If you post some code I might be able to help a bit more.
     
    maiahost, Nov 3, 2006 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you sure that your form method is POST and not GET?

    What happens if you use $_GET instead?

    BTW, if you're assigning one variable to another, you don't need quotes around the second variable.
     
    TwistMyArm, Nov 4, 2006 IP
  6. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    May be this will help.

    <form action="getform.php" method="post">
    <input type="text" class="form1" id="emailaddress" name="emailaddress">
    <input type="submit" value="submit">
    </form>

    Then in "getform.php":
    <?php
    if(trim($_POST['emailaddress']) == "")
    {
    echo "Please enter email";
    }
    else
    {
    $sFromEmailName = $_POST['emailaddress'];
    // then continue with whatever you want to do.
    }
    ?>

    It's not good practice to store email id's in cookies.
    Secondly, above is just an empty check. You must also see if the email id submitted is valid or not.

    Hope this helps you. :)
     
    JEET, Nov 4, 2006 IP
  7. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #7
    Well its a form to firstly have the user input there email address and password to get their hotmail contacts.

    It then displays their email addresses within a tick box to allow them who to send the email to.

    Then has a send button which sends all of those people an email aobut funzac.

    The only problem is i can't for the life of me get the header email too be the same one as the one they input.

    It could be something to do with when they press the second button the stuff input data has been lost??

    <form method="post" action="">
    <input type="text" class="form1" id="emailaddress" name="emailaddress">
    
    
    
    $sFromEmailName = "FunZac.com";
    				$sFromEmail = "referral@funzac.com";
              		$headers  = 'MIME-Version: 1.0' . "\r\n";
              		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
              		$headers .= ' <' . $sEmail . '>' . "\r\n";
              		$headers .= 'From: ' . $sFromEmailName . ' <' . $sFromEmail . '>' . "\r\n";
    Code (markup):
    If i change:
    
    $sFromEmailName = "FunZac.com";
    $sFromEmail = "referral@funzac.com";
    PHP:
    To the input name of the field where the email adress was put in it doesn't work and displays email sent form unkown.
     
    Silver89, Nov 4, 2006 IP
  8. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Your action is empty : action="" in the code above
     
    maiahost, Nov 4, 2006 IP
  9. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #9
    yeh thats because it just reloads the page when it gets to the next step.
     
    Silver89, Nov 4, 2006 IP
  10. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #10
    You are checking $emailaddress not $_POST['emailaddress']. Two different variables.

    Also when you "check" you use double equal sign "==" instead of only one.

    Peace,
     
    Barti1987, Nov 4, 2006 IP
  11. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #11
    Silver89, Nov 4, 2006 IP
  12. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #12
    streety, Nov 4, 2006 IP
  13. Gamer Unlimited

    Gamer Unlimited Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0