View Full Version : error in user form

04-26-2012, 07:42 PM
Hi I am getting this error when I tried and run this coding for a user form I am new to this and need help been messing with this all morning trying to fix the errror nothing I do fixes it.
( ! ) Notice: Undefined index: myusername in C:\wamp\www\check_login.php on line 15
Call Stack
# Time Memory Function Location
1 0.0005 374288 {main}( ) ..\check_login.php:0

( ! ) Notice: Undefined index: mypassword in C:\wamp\www\check_login.php on line 16
Call Stack

$host="localhost"; // Host name
$username="user1"; // Mysql username
$password="password1"; // Mysql password
$db_name="test_db"; // Database name
$tbl_name="test"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or
die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

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


$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword; // after succesfully register the username & password we go to login_success.php header("location:login_success.php");
else{echo" Invalid Username or Password";

heres the form that follows

if ( !isset($_SESSION['myusername']) )
<?php$myusername = $_SESSION['myusername'];
print "Welcome $_SESSION[myusername] \n";
print "Welcome $myusername \n";?>
Login Successful

04-26-2012, 08:27 PM
This is the wrong forum, moving to PHP.


There is no valid post data called myusername or mypassword. Verify the form is using the correct names for the inputs and the method is set to post.
This should be validated and never run unless fields are provided. All of this could (except maybe the config variables if you want) should be wrapped:

if (isset($_POST['myusername'], $_POST['mypassword']))
// do your stuff here