www.webdeveloper.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 46

Thread: Calling data from the database

  1. #31
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    This is what I get

    No username postedNo password posted
    Notice: Undefined variable: username in C:\xampp\htdocs\pixel\profile.php on line 71

    Notice: Undefined variable: password in C:\xampp\htdocs\pixel\profile.php on line 71

    Notice: Undefined variable: username in C:\xampp\htdocs\pixel\profile.php on line 83

    Notice: Undefined variable: password in C:\xampp\htdocs\pixel\profile.php on line 84

  2. #32
    Join Date
    Aug 2012
    Posts
    155
    There you have your answer then, what is the code for your login form (the form, not the php)?

  3. #33
    Join Date
    Aug 2012
    Posts
    155
    Once your form is working as it should (will sort when you post the code) the the login script will be:
    PHP Code:
    <?php

    session_start
    ();

    $username trim($_POST['username']);
    $password trim($_POST['password']);

    if (isset(
    $username) && isset($password))
    {

        
    $connect mysql_connect("localhost","root","") or die ("Could not connect to databade.");
        
    mysql_select_db("login") or die ("Could not find database.");
        
        
    $query mysql_query("SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' and password='".mysql_real_escape_string($password)."' LIMIT 1");
        
        
    $numrows mysql_num_rows($query);
        
        if(
    $numrows != 0
        {
            while (
    $row mysql_fetch_array($query))    
            {
                
    $_SESSION['username'] = $row['username'];
                
    $_SESSION['email'] = $row['email'];
                
    $_SESSION['phone'] = $row['phone'];
                
    $_SESSION['mobile'] = $row['mobile'];
                
    $_SESSION['web'] = $row['web'];
            }    
            
    header("location: home.php");
        }
        else {
            echo 
    "Your username and / or password is incorrect";
        }
    }
    else {
        echo 
    "Please enter a username and password";
    }

    ?>

  4. #34
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    <html>

    <form action="login.php" method="POST">
    <p>Username: <input type="text" name="username"> <p>
    <p>Password: <input type="password" name="password"> <p>
    <input type="submit" name="submit" value="Login">
    </form>


    </html>

  5. #35
    Join Date
    Aug 2012
    Posts
    155
    That is odd as your form looks fine and it is posting to the login page so I cannot see why the login page is not receiving the posted data.

    Can you put
    PHP Code:
    var_dump($_POST); 
    at the top of your login page and post here exactly what you get back?

  6. #36
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    what do you mean what I get back?

  7. #37
    Join Date
    Aug 2012
    Posts
    155
    If you dump the data you should see code at the top of the page - try it and see :-)

  8. #38
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    it shows the
    session_start(); in the top left corner of the screen

  9. #39
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    I am sorry. I added the var dump to the top of the login.php page which is the page that executes when you click login button. and I dont see anything change.

    When I add it to the profile page that all the code has been on I get this at the top left screen
    array(0) { }

  10. #40
    Join Date
    Aug 2012
    Posts
    155
    You shouldn't be able to see the session_start() anywhere on the page, something is wrong with your code there.

    Are you sure you have all your code in login.php (where the form submits to) not a different file?

  11. #41
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    i have fixed the session start issue it does show up in the page anymore. its now set up correctly. I have the code in the login.php set up the way you posted and it works fine. Now once you log in you are redirected to profile.php which is the code we have been echoing out the users information. that is where the errors are coming from.

    profile.php

    </div>
    <div id="profilebio">
    <p>This is where you write a bio about guess who? you!!!</p>

    <?php
    $db="login";
    $link = mysql_connect("localhost", "root", "");
    if (! $link)
    die("Couldn't connect to MySQL");

    mysql_select_db($db , $link)
    or die("Couldn't open $db: ".mysql_error());

    $username = mysql_real_escape_string(trim($_POST['username'])); ************************************************The issues our on these two lines... ****************************************** line 59
    $password = mysql_real_escape_string(trim($_POST['password'])); ************************************************The issues our on these two lines... ****************************************** line 60
    $result = mysql_query( "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1")
    or die("SELECT Error: ".mysql_error());

    while ($row = mysql_fetch_array($result)) {

    $_SESSION['username'] = $row['username'];
    $_SESSION['phone'] = $row['phone'];
    $_SESSION['mobile'] = $row['mobile'];
    $_SESSION['email'] = $row['email'];
    $_SESSION['web'] = $row['web'];

    }

    echo "<p><b>Username: " . $_SESSION['username'] . "</b><br>Phone: " . $_SESSION['phone'] . "<br>Mobile: " . $_SESSION['mobile']. "<br>E-mail: " . $_SESSION['email'] . "<br>Web: " . $_SESSION['web']. "</p><hr>";


    mysql_close($link);
    ?>

    </div>
    </div>

    <div id="footer".
    <?php include('footer.php'); ?>
    </div>

    </body>
    </html>


    <div id="footer".
    <?php include('footer.php'); ?>
    </div>


    </body>
    </html>

    The session start is in the memberarea.php page which is included on this page.

    And this is the output on the page


    Notice: Undefined index: username in C:\xampp\htdocs\pixel\profile.php on line 59

    Notice: Undefined index: password in C:\xampp\htdocs\pixel\profile.php on line 60
    Username: hahaha
    Phone: 817-777-5125
    Mobile: 817-235-2412
    E-mail: hahaha@haha
    Web: http://www.tattooworld.com
    Last edited by Nicholas Diaz; 08-27-2012 at 05:34 AM.

  12. #42
    Join Date
    Aug 2012
    Posts
    155
    I am totally confused - your login form goes to login.php, not profile.php and that is where your login script should be.

    Why do you have the same login code in profile.php?

  13. #43
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    hahahahah cause I am horrible man. and luckily because of your patience and skill its 100 percent fixed... thank you man. I wish there was some way i could repay you for all your time.. seriously your generosity is just amazing.

    Thank you for everything.

  14. #44
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    Maybe you can tell me... from here on out I have lots of things to add should I start a new thread for each thing or just continue on here???

  15. #45
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    Now the information is displaying on the profile page correctly I need to add a button next to the information being echo that allows them to edit their information then resubmit it to the data base making the changes to the rows that it is stored in.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles