SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question now this is really a stupid post but I really need to know

    Sorry for the stupid post :\ I have kinda got a thing for stupid posts

    well any way... to the point.

    Code:
    function displayLogin(){
       global $logged_in;
       if($logged_in){
          echo "<h1>Logged In!</h1>";
          echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
          echo "<b>Cash: </b><i>$Cash </i><b>Email: </b><i>$email</i>";
    With that code I dont see "Cash: </b><i>$Cash" or "<b>Email: </b><i>$email</i>" on the page that I want them to show up.

    So I really need help in getting my php script to print contense from my database tables Cash and email.
    It seems to be easy but its not for me cause I'm just starting and I AM A BL**DY N00B DARN IT

    Phew glad I got that off my chest

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function displayLogin(){
    global 
    $logged_in;
    if(
    $logged_in){
    echo 
    "<h1>Logged In!</h1>";
    echo 
    "Welcome <b>".$_SESSION[username]."</b>, you are logged in. <a href='logout.php'>Logout</a>";
    echo 
    "<b>Cash: </b><i>".$Cash."</i><b> Email: </b><i>".$email."</i>";
    }

    u missed the concatenation...
    cheers

  3. #3
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u missed the concatenation...
    shouldnt matter. he was using double quotes...

    are u sure you have assigned values to $Cash and $email?

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like you need to add $Cash, $email (and probably the $_SESSION variable too) as parameters to your function; something like:

    PHP Code:
    function displayLogin($user$sqlArray){
       global 
    $logged_in;
       if(
    $logged_in){
          echo 
    "<h1>Logged In!</h1>";
          echo 
    "Welcome <b>$user</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
          echo 
    "<b>Cash: </b><i>$sqlArray[Cash] </i><b>Email: </b><i>$sqlArray[email]</i>"
    then call it like this:

    PHP Code:
    //mysq_query - mysql_fetch_array gives $resultSet

    displayLogin($_SESSION[username], $resultSet); 

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function displayLogin($logged_in$Cash$email){
    if(
    $logged_in){
    echo 
    "<h1>Logged In!</h1>";
    echo 
    "Welcome <b>".$_SESSION[username]."</b>, you are logged in. <a href='logout.php'>Logout</a>";
    echo 
    "<b>Cash: </b><i>".$Cash."</i><b> Email: </b><i>".$email."</i>";
    }

    cheers

  6. #6
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the full php file's code in the code box below
    Code:
    <?
    
    /**
     * Checks whether or not the given username is in the
     * database, if so it checks if the given password is
     * the same password in the database for that user.
     * If the user doesn't exist or if the passwords don't
     * match up, it returns an error code (1 or 2). 
     * On success it returns 0.
     */
    function confirmUser($username, $password){
       global $conn;
       /* Add slashes if necessary (for query) */
       if(!get_magic_quotes_gpc()) {
    	$username = addslashes($username);
       }
    
       /* Verify that user is in database */
       $q = "select password from users where username = '$username'";
       $result = mysql_query($q,$conn);
       if(!$result || (mysql_numrows($result) < 1)){
          return 1; //Indicates username failure
       }
    
       /* Retrieve password from result, strip slashes */
       $dbarray = mysql_fetch_array($result);
       $dbarray['password']  = stripslashes($dbarray['password']);
       $password = stripslashes($password);
    
       /* Validate that password is correct */
       if($password == $dbarray['password']){
          return 0; //Success! Username and password confirmed
       }
       else{
          return 2; //Indicates password failure
       }
    }
    
       $c = "SELECT Cash FROM users WHERE username = '$username'";
       $Cash = 'mysql_query($c,$conn)';
    
       $e = "SELECT email FROM users WHERE username = '$username'";
       $email = 'mysql_query($e,$conn)';
    
    /**
     * checkLogin - Checks if the user has already previously
     * logged in, and a session with the user has already been
     * established. Also checks to see if user has been remembered.
     * If so, the database is queried to make sure of the user's 
     * authenticity. Returns true if the user has logged in.
     */
    function checkLogin(){
       /* Check if user has been remembered */
       if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
          $_SESSION['username'] = $_COOKIE['cookname'];
          $_SESSION['password'] = $_COOKIE['cookpass'];
       }
    
       /* Username and password have been set */
       if(isset($_SESSION['username']) && isset($_SESSION['password'])){
          /* Confirm that username and password are valid */
          if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){
             /* Variables are incorrect, user not logged in */
             unset($_SESSION['username']);
             unset($_SESSION['password']);
             return false;
          }
          return true;
       }
       /* User not logged in */
       else{
          return false;
       }
    }
    
    /**
     * Determines whether or not to display the login
     * form or to show the user that he is logged in
     * based on if the session variables are set.
     */
    function displayLogin(){
       global $logged_in;
       if($logged_in){
          echo "<h1>Logged In!</h1>";
          echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
          echo "<b>Cash: </b><i>.$Cash. </i><b>Email: </b><i>.$email.</i>";
          
       }
       else{
    ?>
    
    
    <h1><font color="#800000"><span style="background-color: #FFFF00">Login</span></font></h1>
    <form action="" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3" bgcolor="#FFFF00" style="border-collapse: collapse" bordercolor="#111111">
    <tr><td>Username:</td><td>
      <input type="text" name="user" maxlength="30" size="20" style="color: #00FF00; border: 1px solid #800000; background-color: #FFFF00"></td></tr>
    <tr><td>Password:</td><td>
      <input type="password" name="pass" maxlength="30" size="20" style="color: #00FF00; border: 1px solid #800000; background-color: #FFFF00"></td></tr>
    <tr><td colspan="2" align="left">
      <input type="checkbox" name="remember" value="ON" style="color: #00FF00; background-color: #FFFF00">
    <font size="2">Remember me next time</td></tr>
    <tr><td colspan="2" align="right">
      <input type="submit" name="sublogin" value="Login" style="color: #800000; border: 1px solid #800000; background-color: #808000"></td></tr>
    <tr><td colspan="2" align="left">
      <a href="register.php" style="text-decoration: none"><font color="#FF5050">Join</font></a></td></tr>
    </table>
    </form>
    
    
    <?
       }
    }
    
    
    /**
     * Checks to see if the user has submitted his
     * username and password through the login form,
     * if so, checks authenticity in database and
     * creates session.
     */
    if(isset($_POST['sublogin'])){
       /* Check that all fields were typed in */
       if(!$_POST['user'] || !$_POST['pass']){
          die('You didn\'t fill in a required field.');
       }
       /* Spruce up username, check length */
       $_POST['user'] = trim($_POST['user']);
       if(strlen($_POST['user']) > 30){
          die("Sorry, the username is longer than 30 characters, please shorten it.");
       }
    
       /* Checks that username is in database and password is correct */
       $md5pass = md5($_POST['pass']);
       $result = confirmUser($_POST['user'], $md5pass);
    
       /* Check error codes */
       if($result == 1){
          die('That username doesn\'t exist in our database.');
       }
       else if($result == 2){
          die('Incorrect password, please try again.');
       }
    
       /* Username and password correct, register session variables */
       $_POST['user'] = stripslashes($_POST['user']);
       $_SESSION['username'] = $_POST['user'];
       $_SESSION['password'] = $md5pass;
    
       /**
        * This is the cool part: the user has requested that we remember that
        * he's logged in, so we set two cookies. One to hold his username,
        * and one to hold his md5 encrypted password. We set them both to
        * expire in 100 days. Now, next time he comes to our site, we will
        * log him in automatically.
        */
       if(isset($_POST['remember'])){
          setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
          setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
       }
    
       /* Quick self-redirect to avoid resending data on refresh */
       echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
       return;
    }
    
    /* Sets the value of the logged_in variable, which can be used in your code */
    $logged_in = checkLogin();
    
    ?>
    It just wont show the variables. It will show as Cash: ..email:..

    hope one of you guys could sort this problem out.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function displayLogin($Cash$email) {
    global 
    $logged_in;
    if(
    $logged_in){
    echo 
    "<h1>Logged In!</h1>";
    echo 
    "Welcome <b>".$_SESSION[username]."</b>, you are logged in. <a href='logout.php'>Logout</a>";
    echo 
    "<b>Cash: </b><i>".$Cash."</i><b> Email: </b><i>".$email."</i>";
    }

    this should work...
    cheers

  8. #8
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry didn't work.
    displayLogin() is a function and it came up with a missing argument.

    Warning: Missing argument 1 for displaylogin() in /home/gfun/public_html/test/test_2/login.php on line 81

    Warning: Missing argument 2 for displaylogin() in /home/gfun/public_html/test/test_2/login.php on line 81
    whats the command to display all errors and debug for php? that may help me a bit.

  9. #9
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any one able to give me the php code to show all errors in a php script?

  10. #10
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    error_reporting
    Is your $_SESSION[username] set?

  11. #11
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys for all your help. I got the error command thingy with a bitta help from my mate down the corner and fixed the problem.

    If any one wants to see what i have been up to then please see for your self...
    username: test
    password: test
    http://gfun.ahazhosting.com/test/test_2/main.php

    But Don't sign up for your own account! This is only on a test server and accounts will not be transferd over to the official server. If any php coders wish to help me they will not go with out a reward... it may sound crummy but well... I am a underaged webmaster so I cant offer you anything but data.

    PhP coder's reward will be an account with unlimated cash and I will place adverts to there website on mine.
    Last edited by Manoverthere; Dec 12, 2004 at 22:14.


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
  •