rose34ll2
04-26-2012, 06: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
<?php
$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
session_start();
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// 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
password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_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
<?
session_start();
if ( !isset($_SESSION['myusername']) )
{
header("location:main_login.php");
}
?>
<html>
<body>
<?php$myusername = $_SESSION['myusername'];
print "Welcome $_SESSION[myusername] \n";
print "Welcome $myusername \n";?>
Login Successful
</body>
</html>
( ! ) 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
<?php
$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
session_start();
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// 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
password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_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
<?
session_start();
if ( !isset($_SESSION['myusername']) )
{
header("location:main_login.php");
}
?>
<html>
<body>
<?php$myusername = $_SESSION['myusername'];
print "Welcome $_SESSION[myusername] \n";
print "Welcome $myusername \n";?>
Login Successful
</body>
</html>