errors with log-in processing page

Discussion in 'PHP' started by geneh23, Dec 24, 2011.

  1. #1
    Hey everyone!

    I am fairly new to php but still consider myself a beginner. I have a checkuser.php to process info inputted through a form. I have done echo statements to echo out some variables to see what shows due to me having an issue not getting processed right..it tells me that "the user does not exist". So in return I've echoed out some variables to see where the issue is..for some reason the variable "dbpassword" does not apear and there is an error that says as follows
    "Notice: Undefined variable: dbpassword in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Sample\checkuser.php on line 45"

    Here is the checkuser.php
    <?phpsession_start();
    // username and password sent from form $username=$_POST['username']; $password= md5($_POST['password']);
    echo "Here is the username from form: <b>$username</b></br></br>";echo "Here is the password from form: <b>$password</b></br></br>";
    if($username&&$password){
    $connect = mysql_connect("********","******","******") or die("could not connect!");mysql_select_db("*******") or die("Could not find db!");
    $query = mysql_query("SELECT * FROM users WHERE username='$username' AND Password = '".md5($password)."'");echo "Here is the query: <b>$query</b></br>";
    $numrows = mysql_num_rows($query);
    if($numrows!==0){    while ($row = mysql_fetch_assoc($query))    {        $dbusername = $row['username'];        $dbpassword = $row['password'];    }    echo "Here is the db username: <b>$dbusername</b></br></br>";    echo "Here is the db password: <b>$dbpassword</b></br></br>";    if($username==$dbusername&&$password==$dbpassword)    {        echo "You're in!";
    
    
        }    else        echo "<b>Incorrect password!</b></br></br>";}else    echo "Here is the username sent from form: <b>$username</b></br></br>";    echo "Here is the dbusername: <b>$username</b></br></br>";    echo "Here is the password sent from form: <b>$password</b></br></br>";    echo "Here is the dbpassword: <b>$dbpassword</b></br></br>";    die("That user does not exist!");
    
    }else    die("Please enter username and password!");
    ?>
    PHP:
    and here are the echo statements that show on the page as they apear in the checkuser.php

    "Here is the username from form: *****

    Here is the password from form: **********************************

    Here is the query: Resource id #4
    Here is the username sent from form: *****

    Here is the dbusername: *****

    Here is the password sent from form: *********************


    Notice: Undefined variable: dbpassword in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Sample\checkuser.php on line 45
    Here is the dbpassword:

    That user does not exist!
    "

    any help would be greatly appreciated!!
     
    geneh23, Dec 24, 2011 IP
  2. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #2
    first of all,

    Notice: Undefined variable: dbpassword in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Sample\checkuser.php on line 45

    this is because u cannot access variable defined in IF section in the ELSE part



    secondly.... u r comparing 'password' with with 'dbpassword' but as i can see in ur query, the password in database is md5'ed... right??? so how will it match with ur 'password' variable which is a simple text???????
     
    Rising_Star, Dec 25, 2011 IP
  3. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #3
    and there is still more to write....

    else echo "Here is the username sent from form: <b>$username</b></br></br>";
    echo "Here is the dbusername: <b>$username</b></br></br>";
    echo "Here is the password sent from form: <b>$password</b></br></br>";
    echo "Here is the dbpassword: <b>$dbpassword</b></br></br>";
    die("That user does not exist!");

    u see, this part is not in brackets... so "the user does not exist is going to be echo'ed anyway... even if there are ten results found
     
    Rising_Star, Dec 25, 2011 IP
  4. geneh23

    geneh23 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I figured since the database password id md5'd that I needed to md5 it to enter into the database so It would match with I compare it for the log in process..

    what does "Resource id #4" mean? and I put the else statement in brackets but I still ended up with the message, "user does not exist" :/
     
    geneh23, Dec 25, 2011 IP
  5. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #5
    can u post ur latest code?
     
    Rising_Star, Dec 25, 2011 IP
  6. geneh23

    geneh23 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?phpsession_start();
    // username and password sent from form $username=$_POST['username']; $password= md5($_POST['password']);
    if($username&&$password){
    $connect = mysql_connect("*********","****","*****") or die("could not connect!");mysql_select_db("****") or die("Could not find db!");
    $query = mysql_query("SELECT * FROM users WHERE username='$username' AND Password = '".md5($password)."'");echo "Here is the query: <b>$query</b></br>";
    $numrows = mysql_num_rows($query);
    if($numrows!==0){	while ($row = mysql_fetch_assoc($query))	{		$dbusername = $row['username'];		$dbpassword = $row['password'];	}	if($username==$dbusername&&$password==$dbpassword)	{		echo "You're in!";
    
    
    	}	else		echo "<b>Incorrect password!</b></br></br>";}else {	die("That user does not exist!");}
    }else	die("Please enter username and password!");
    ?>
    PHP:
     
    geneh23, Dec 25, 2011 IP
  7. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #7
    <?phpsession_start();// username and password sent from form $username=$_POST['username']; $password= md5($_POST['password']);if($username!=""&&$password!=""){$connect = mysql_connect("*********","****","*****") or die("could not connect!");mysql_select_db("****") or die("Could not find db!");$query = mysql_query("SELECT * FROM users WHERE username='$username' AND Password = '".md5($password)."'");echo "Here is the query: <b>$query</b></br>";$numrows = mysql_num_rows($query);if($numrows!=0){   while ($row = mysql_fetch_assoc($query))    {       $dbusername = $row['username'];     $dbpassword = $row['password'];   }    if($username==$dbusername&& md5($password)==$dbpassword)  {    echo "You're in!";}   else        echo "<b>Incorrect password!</b></br></br>";		}		else 		{ 		die("That user does not exist!");		}}else   die("Please enter username and password!");?>
    PHP:
     
    Rising_Star, Dec 27, 2011 IP
  8. geneh23

    geneh23 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, so I've rewritten everything and now I have another issue..I've placed some php at the top of a page before an before some html tags..however there are some errors that show..but when I test it out with a test site, it works fine..here are the errors..

    "Notice: Undefined index: username in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 5

    Notice: Undefined index: password in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 6

    Notice: Undefined index: Submit in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 10
    "

    and here is the index.php page
    <?php
    session_start();
    $user = $_POST['username'];$pass = $_POST['password'];mysql_connect("******","*****","*****");mysql_select_db("******");
    if($_POST['Submit']){$select = "SELECT * FROM ****** where username='".$_SESSION['$user']."' && password='".$_SESSION['$pass']."'";$msq = mysql_query($select); if(mysql_num_rows($msq)>0)    {    while($row = mysql_fetch_array($msq))          {            $username = $row['username'];            session_start();            $_SESSION['username'] = $username;            echo $_SESSION['username'];                        }            header("location: checkuser.php");   }}
    
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title></title><link rel="stylesheet" type="text/css" href="CSS/style.css" /><meta name="description" content="This book will give women, men, and teenagers a different perspective on pregnancy and your life immediately following having kids. This story describes my overall experience being pregnant. This book will prepare all women to make sure that they are ready to get pregnant! I hope you enjoy!!!" /><meta name="keywords" content="Tahirih Pellegrino,teen,teen mother,TEEN MOTHER,struggle,life,Baby,babysitting,childbirth,pregnancy,giving birth,hospital,health,mom,being a mom,parent,being a parent,Ready or Not,books,story,blog,blogs,email,family," /><script type="text/javascript">function preload(arrayOfImages) {    $(arrayOfImages).each(function(){        $('<Images/>')[0].src = this;        // Alternatively you could use:        // (new Images()).src = this;    });}
    // Usage:
    preload([    'Images/butterfly-background.jpg',    'Images/book cover2 another version1.jpg',    'Images/facebook-logo-pink.png'    'Images/Email-icon.jpg'    'Images/header-background.jpg'    'menu-background.jpg']);</script> </head><body><div class="container"><div id="main-pic"><a href="AboutMe.html"><div id="main-pic-background"><img src="Images/Tahirih.jpeg" width="240px" height="327px" /></div><!-- end of #main-pic-background --></a></div><!-- end of #main-pic --><div id="side-pic1"><a href="#"><table style="margin-left: 4px; margin-top: 4px;" border="0" width="204px" height="54" cellpadding="0" cellspacing="0">       <tr>    <td style="border-top: 1px solid purple; border-left: 1px solid purple; border-bottom: 1px solid purple; padding-left: 5px; padding-right: 15px;"><img src="Images/facebook-logo-pink.png" width="38px" height="38px" /></td>    <td style="border-top: 1px solid purple; border-right: 1px solid purple; border-bottom: 1px solid purple; color: #000;">Become A Fan of Tahirih on Facebook</td>       </tr></table></a></div><!-- end of #sid-pic1 --><div id="side-pic2"><a href="EmailForm.php" target="_blank"><div class="inner-side-pic2"><img src="Images/Email-icon.jpg" width="50px" height="40px" /><div class="inner-side-pic2-text">Shoot Tahirih an Email!!<!-- end of .inner-side-pic-text --></div></div><!-- end of .inner-side-pic2 --></a></div><!-- end of #side-pic2 --><div id="side-pic3"><a href="Buy.php"><img src="Images/book cover2 another version1.jpg" width="210px" height="300px" /></a></div><!-- end of #side-pic3 --><div id="side-pic4"><div class="inner-side-pic4"><h3 style="font-size: 20px; font-weight: bold; margin-left: 10px;"><u>On Sale Nov. 2nd, 2011</u></h3><p class="pic-4-description">Order "Ready Or Not" at these online retalers:</p><ul>    <li><a href="#">amazon.com</a></li>    <li><a href="#">ebay.com</a></li></ul></div><!-- end of .inner-side-pic4 --></div><!-- end of #side-pic4 --><div id="side-pic5"><div class="inner-side-pic5"><div class="inner-side-pic5-text"><h3 style="font-size: 20px; font-weight: bold; margin-left: 10px;"><u>Recent Blog Posts</u></h3><ul>    <li><span class="headline"><b>No blogs Have been posted at this time.<b></span></li><br />    <li><span class="headline">Please check back later for more updates!</b></span></li></ul></div><!-- end of inner-side-pic4-text --></div><!-- end of .inner-side-pic5 --></div><!-- end of #side-pic5 --><div id="header"><div id="nav-header"><a href="index.php"><h1><i>Tahirih Pellegrino</i></h1><h2><i><u>Ready or Not!!</u></i></h2></a></div><!-- end of nav-header --></div><!-- end of #header --><div id="menu"><ul><li><a href="index.php">Home</a></li><li><a href="Register1.php">Register</a></li><li><a href="AboutMe.html">About Me</a></li><li><a href="Blog.php">Blog</a></li><li><a href="Buy.php">Buy Now</a></li><li><a href="ContactMe.html">Contact Me</a></li><li><a href="logout.php">Sign Out</a></li></ul></div><!-- end of #menu --><div id="content"><div id="login-content"><u>Log In</u><form action="checkuser.php" method="post" name="" id="">Username:<br /><input size="10" type="text" name="username" id="username" /><br />Password:<br /><input size="10" type="password" name="password" id="password" /><br /><input type="submit" name="Submit" value="Submit"></form>
    </div><!--end of #login-content--><div id="inner-content"><div class="subnav"><p>Latest News...</p><div id="main-content"><h2><i>Ready Or Not, my 1st story, on sale now!</i><br /></h2><br /><hr size="1px" color="#cccccc" /><br /><h2><a href="Buy.php">Ready or Not!!</a></h2><h3>Ready or Not, came out Nov. 2nd, 2011. <a href="Buy.php">Order</a> your copy today!!<br /><br /><br /><hr size="1px" color="#cccccc" /><br /><h2><a href="Blog.php">Blog</a></h2><h3>Here, I will post various topics pretaining to my experiences and would very much appreciate feedback commentary if desired.</h3><br /><hr size="1px" color="#cccccc" /><br /><h2><a href="#">Reach Me!!</a></h2><h3>I have an active <a href="#">Facebook</a> page dedicated to my book, where I interact with my readers as well as on here. You can also get information from my <a href="Blog.php">blog</a>. Lets get the conversation started!!</h3><br /><hr size="1px" color="#cccccc" /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><div style="clear: both;"></div></div><!-- end of #main-content --></div><!-- end of #inner-content --></div><!-- end of #content --><div id="footer"><div class="left">&copy; 2011 Tahirih Pellegrino, All Rights Reserved</div><!-- end of .left --><div class="right">Web Design by <a href="http://www.facebook.com/pages/Gene-Howell/166880296733102?sk=info" target="_blank">Gene Howell</a>. Hosting by <a href="http://www.godaddy.com/default.aspx" target="_blank">Godaddy.com</a></div><!-- end of .right --></div><!-- end of #footer --></div><!-- end of .container --></body></html>
    HTML:
    Thanks for any help!
     
    geneh23, Dec 29, 2011 IP