0

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">
    Username:
</td>
<td><input type="text" size="40" id="username" class="inputbox" /></td>
 </tr>
<tr>
<td align="right">
 Password:
</td>
<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'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
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"] : "";

Error:

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.

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by raphie
0

I have noticed something wrong with your form.

<td align="right" width="130px">
    Username:
    </td>
    <td><input type="text" size="40" id="myusername" class="inputbox" /></td>
    </tr>
    <tr>
    <td align="right">
    Password:
    </td>
    <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.

0

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

Edited by abelingaw: n/a

0

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') ){

DO SOMETHING 

}else{

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

}
0

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:

print_r($_POST)

Edited by raphie: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.