Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Learning Sessions

    Now that I've finally figured out what I need to be learning it is sessions.

    (explaining the purpose of the code)

    The form is real simple. The customer will only put in the amount they want.

    Code:
    <form action="order.php" method="post" style="height: 460px">
    	order01<input name="order01" style="width: 40px" type="text" /> <br />
    	order02<input name="order02" style="width: 40px" type="text" /><br />
    	order03<input name="order03" style="width: 40px" type="text" /><br />
    	<br />
    	<input type="submit" value="Submit"onclick="return confirm('Are you sure you want to submit the form?');" />			
    	<input name="reset" id="reset" type="reset" value="Reset" />
    	</form>
    The php will only print what is ordered and leave out any '0's it encounters.
    Now what I don't know how to do is get information from this php (Confirmation Page) to the email. All I want is only the information that is printed on the confirmation page. I've tried to read up on sessions but i don't comprehend it that well. If anyone can show me an example based upon this code I can learn it. Thanks to all that have any comments or critiques.


    PHP Code:
    <?php
    $order01 
    $_POST["order01"];
    $order02 $_POST["order02"];
    $order03 $_POST["order03"];

    if ( 
    $order01 ) {
        echo 
    " amount of $order01 <br />";
    }

    if ( 
    $order02 ) {
        echo 
    " amount of $order02 <br />";
    }

    if ( 
    $order03 ) {
        echo 
    " amount of $order03 <br />";
    }
    ?>
    <html>
    <body>
    <form method="post" action="">
    <input type=button value="Back" onClick="history.go(-1)">
    <input name="Submit" type="submit" value="Place Order" onClick="testResults(this.form)">
    </form>
    </body>
    </html>

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Post values to email;
    PHP Code:
    // Subject.
    $subject 'Results from Contact form'
    // Email address.  
    $emailadd 'mail@example.com'

    // Redirect after the form is processed. 
    $url='confirmation.php'

    //Do not edit below this line
    $text "Results from form:\n\n"
    $space ' ';
    $line '';
    foreach (
    $_POST as $key => $value){
    for (
    $i 1$i++){
    $space .= ' ';}
    $value str_replace('\n'"$line"$value);
    $conc "{$key}:$space{$value}$line";
    $text .= $conc;
    $space ' ';
    }
    mail($emailadd$subject$text'From: '.$emailadd.'');
    echo 
    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #3
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    regarding sessions, in a nutshell

    PHP Code:
    session_start();  // must be at the TOP of EVERY page you want to use sessions on.

    /* in its simplest form. here we set some session variables */

    $_SESSION['username'] = 'met';
    $_SESSION['age'] = 21;

    echo 
    'My username is ' $_SESSION['met'] . ' and I am ' $_SESSION['age'];
    // outputs My username is met and I am 21

    unset($_SESSION['username']); // unsets the value

    echo $_SESSION ['username']);
    // outputs nothing.

    session_destroy();
    /* destroys all sessions and all data is lost */ 
    sessions are used to store data and transfer it across multiple pages (as well as other functions)

    some examples: storing the contents of a shopping cart, authenticated user details, page viewing history, user preferences...

    you can set a session by assigning it a value literally, or assigning it from $_GET or $_POST (using forms eg)

    in your example above when the user submits the form you could set a session value to be equal to the amount they entered, and then use that information on another page later on.

    $_SESSION[] is an array, much like $_GET and $_POST, you set and access the values the same way. The main difference is that SESSION will last for the duration of, well, the users session, whereas GET and POST have less scope, i.e only the form(s) they are used in.

    the most important thing when dealing with sessions is to remember to put
    PHP Code:
    <?php 
    session_start
    (); 

    /*  your script */
    at the very top of every page youwant to use sessions in.
    Last edited by met; 11-01-2009 at 08:58 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •