Jump to content

Undefined Variable


Nikk

Recommended Posts

Hey guys, I've been coding PHP for about two weeks now, so excuse the appalling code. Here is the error message

Notice: Undefined variable: dbusername in C:\wamp\www\twitbiscuit\process.php on line 25

 

Here is a pastie link to my code, thanks in advance.

http://pastie.org/1076001

 

( The fact my first post is asking for help, fail. )

Link to comment
Share on other sites

 $row = mysql_fetch_assoc($query);
         $dbusername = $row['username'];
         $dbpassword = $row['password'];

 

should be:

while($row = mysql_fetch_assoc($query)){;
         $dbusername = $row['username'];
         $dbpassword = $row['password'];
}

Link to comment
Share on other sites

A notice is nothing realy to worry about but ideally you'd want to strive to eliminate them.

 

All it means is that you're accessing something [variable] that hasn't yet been set.

 

In your case one or more of those variables are being referenced without being defined.

Link to comment
Share on other sites

Sorry, mgallforever, still half dead. Long day at work and I wasn't paying attention very well.

 

As for the problem at hand you may want to put your if ($username==$dbusername&&$password==$dbpassword) statement into the if ($username&&$password) statement:

 

//setting the first variables
$username = $_POST['username'];
$password = $_POST['password'];


if ($username&&$password)
{
    // connecting
    $connect = mysql_connect("localhost","root","") or die ("couldn't connect");
    mysql_select_db("phplogin") or die ("no sign of db");

    $query = mysql_query("SELECT * FROM users WHERE username='$username'");

    $numrows = mysql_num_rows($query);

        $row = mysql_fetch_assoc($query);
         $dbusername = $row['username'];
         $dbpassword = $row['password'];
     
     // check to see if they match!
     if ($username==$dbusername&&$password==$dbpassword)
        echo "logged in! <a href='member.php'>Click</a> view your live feed";
     else
         echo "Login failed, check username and password";

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.