SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: POST help

  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    POST help

    I have a member login page that pulls items from a database that they are selling. I want to have a change password, change address, change phone number, etc. link to a page which a form for the appropriate change, ie: change_address.php. Now I am having problems posting the username and password to a second teir page, ie change_address.php so that I can perform the proper query from the database. I know that I can do it through GET- but there is proably a better solution. I need to pass the username to a page so they can change their contact info. Im still learning on how applications are structured, so I will gladly take any advice!

    Login form goes to Member.php below:
    PHP Code:
    <?
    $username 
    $_POST['username'];
    $passwd $_POST['passwd'];

    if (
    $username && $passwd){
    if (
    login($username$passwd)){
    session_start();
    $_SESSION['valid_user'] = $username;
    require_once(
    'welcome.php');
    }else{
    require_once(
    'failure.php');
    }
    }
    function 
    db_connect()
    {
    //$result = mysql_pconnect('localhost', 'xXxXxX', 'xXxXxX');
    //lets just try this this one because mysql_pconnect() opens a persistent connection
    $result mysql_connect('localhost''xxxxxx''xxxxxxx');
    if (!
    $result)
    return 
    false;
    if (!
    mysql_select_db('onestop_bookmarks'))
    return 
    false;

    return 
    $result;
    }
    function 
    login($username$passwd){

    $conn db_connect();
    if (!
    $conn)
    return 
    false;
    $result mysql_query("select * from user
    where username='
    $username'
    and passwd = password('
    $passwd')");
    if (!
    $result)
    return 
    false;

    if (
    mysql_num_rows($result)>0)
    return 
    true;
    else
    return 
    false;


    ?>
    On successful login, require_once welcome.php
    WELCOME.PHP
    PHP Code:
    <?
    $username 
    $_POST['username'];
    $passwd $_POST['passwd'];
    ?>
    //HTML for welcome.php- basic structure


    <a href="address_edit.php">edit</a>  //how do i POST the username, to retrieve it on this page?
    <a href="phone_edit.php">edit</a> // how do i POST username??
    <a href="address_edit.php">edit</a> // how do i POST username?
    address_edit.php
    PHP Code:

    <?
    $username 
    $_POST['username'];
    $passwd $_POST['passwd'];

    ?>

    Welcome $username  //this wont post the username from the previous page, member.php... how do i post the username to retrive it on this page?


    <form name="form1" method="post" action="address_edit2.php">
                        <table width="200" border="0" cellspacing="0" cellpadding="4">
                          <tr> 
                            <td>Email:</td>
                            <td><input name="address" type="text" id="address"></td>
                          </tr>
                          <tr> 
                            <td>&nbsp;</td>
                            <td><div align="right"> 
                                <input type="submit" name="Submit" value="Submit">
                              </div></td>
                          </tr>
                        </table>
                      </form>

    Any advice would be appreciated. I only posted basic html, but all of these pages are within tables and tables and Im not sure how to make one application that just swapps out the guts of a page over a basic template. ie- an application that will log you in and pull info from a database, when a link is clicked a function takes over and replaced the welcome info with a form to change their contact info. Upon submitting the change they would be taken back to their welcome page. Could all this be done in one application or would it be multiple pages, one page to change email, one page to change phone number, one page to change address, etc.

    I guess you could do it any way you design it, however Im not too sure the best routes to take despite dedicated hours of accumilating wrinkles.

    Regards,
    Kevin

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, In member.php you store the username as a session. So as long as you have session_start() on your other page you can acces the username using the $_SESSION['valid_user']

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this?

    PHP Code:
    <?
    session_start
    ();
    $_SESSION['valid_user']
    $username $_POST['username'];
    $passwd $_POST['passwd'];

    ?>

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    No, like this:

    PHP Code:
    <?php
    session_start
    ();
    $username $_SESSION['valid_user'];

    // the rest of your script
    The POST variables will disappear when the location is changed but the session variables will be accessible as long as you have session_start() at the top of all your pages.

    Yours, Erik.

  5. #5
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks AAAAAAAAA-LOT!


Bookmarks

Posting Permissions

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