SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Total Newbie with Strings

    Having a problem.

    If I have this mysql query
    PHP Code:
        $sql 'SELECT id, firstname, lastname, username, password FROM Members 
    How do I get the id = $id and firstname = $firstname etc etc???

    I can't find the answer. Sorry for daft question.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sql "SELECT id, firstname, lastname, username, password FROM Members WHERE id='$id' AND firstname='$firstname'"
    Don't forget to validate the user input first

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I probably misled you.

    What I want to do is carry all the obtained details from members (in a session) to another web page. In that web page I want it to say "Welcome $firstname $lastname"

    So, I need to put the firstname and lastname into a $string - does that make sense? The following is the complete php script if that helps. It already carries forward in the session the username and password, but I also want it to carry forward all the other information - if possible.

    PHP Code:
          // if no errors carry on.
          
    if('' == $error_msg
          {
             
    $sql 'SELECT id, firstname, lastname, username, password FROM Members WHERE';
             
    $sql .= ' username = \'' $username '\'';
             
    $sql .= ' AND ';
             
    $sql .= ' password = \'' $password '\'';
          
    $login_check mysql_query($sql);
          
          if (
    false === $login_check)
          {
              
    $error_msg .= $sql ' failed due to ' mysql_error() . '<br />'
          }
          else
          {
            
    // get the rows from the database
            
    $login_rows mysql_num_rows($login_check);
        
             
    // there should be only 1 row in the database for this username / password combination
            
    if(== $login_rows)
            {
              
    // define session variables
              
    $_SESSION['login'] = 'Logged';
              
    $_SESSION['username'] = $username;
              
    $_SESSION['password'] = $password;
              
    // redirect
              
    header('Location: memberhome.php');
              exit; 

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $row mysql_fetch_assoc($login_check);
    $_SESSION['firstname'] = $row['firstname'];
    $_SESSION['lastname'] = $row['lastname'];
    $_SESSION['login'] = 'Logged';
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password
    Then over on member.php
    PHP Code:
    echo "Welcome $_SESSION['firstname'] $_SESSION['lastname']"

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code i've placed in memberhome.php but it comes up with

    Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in memberhome.php on line 13


    Line 13
    PHP Code:
    <p align="center">Welcome <?php echo $_SESSION['firstname'$_SESSION['lastname'] ; ?> </p>

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh well. try this:
    PHP Code:
    <p align="center">Welcome <?php echo $_SESSION['firstname'] . " " $_SESSION['lastname']; ?> </p>

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect!

    Excellent - thank you very much!!! Appreciated!


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
  •