I'm having problem with my login php files.

I don't know if it is in the passing of values from inputboxes or connection with my database records.

log-in code:

<td align="right" width="130px">
<td><input type="text" size="40" id="username" class="inputbox" /></td>
<td align="right">
<td><input type="password" size="40" id="password" class="inputbox" /></td>

Login checking code:

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";


else {
echo "Wrong Username or Password";

And the line producing the error is this:

$myusername=isset($_POST['myusername']) ? $_POST["myusername"] : ""; 
$mypassword=isset($_POST['mypassword']) ? $_POST["mypassword"] : "";


Fatal Error:Undefined index: myusername
Undefined index: mypassword

The myusername in POST method is same name of my inputboxes on the login page same as mypassword.

Tried isset but still won't get the right output.
And i'm entering the correct records from my DB.

Recommended Answers

All 5 Replies

I have noticed something wrong with your form.

<td align="right" width="130px">
    <td><input type="text" size="40" id="myusername" class="inputbox" /></td>
    <td align="right">
    <td><input type="password" size="40" id="mypassword" class="inputbox" /></td>

OK. Change the IDs for password to mypassword and for username to myusername. Try this and I'm sure it will work. The reason I'm telling you to do so Because you have got different names that don't match the names in your query.

Done but still..

Getting the message in the echo part.

echo "Wrong Username or Password";

I'm using correct username and password from DB and DB name and tables are declared correctly

Change the attribute ID to name in your form. This will fix the problem. If it doesn't, then try the steps below:

Delete the $ sign before table name in your query

$sql="SELECT * FROM tbl_name WHERE username='$myusername' and password='$mypassword'";
if $count => 1

then Try checking if the username and password are typed.

$mypassword = $_POST['mypassword'];
$myusername = $_POST['myusername'];

if ( isset('$mypassword') && isset('$myusername') ){



echo "username: $myusername and password: $mypassword  are not correct";


if this solves your problem, please kindly mark it as a solved thread.

Try to use instead of id="myusername" use name="myusername", depending how you processing the form and the server you are using, sometimes cause problems. $_POST is normally set by the name of the input not the id. In some systems a nameless input is considered disabled an pass no values.

You can try seeing what's the post with:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.