PHP login form issue with coding -
notice: undefined index: myusername in c:\xampp\htdocs\login_in2.php on line 14 wrong username or password
<?php $host="localhost"; // host name $username="root"; // mysql username $password=""; // mysql password $db_name="test"; // database name $tbl_name="members"; // table name // connect server , select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); // username , password sent form $myusername=$_post['myusername']; $mypassword=$_post['mypassword']; // protect mysql injection (more detail mysql injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="select * $tbl_name username='$myusername' , password='$mypassword'"; $result=mysql_query($sql); // mysql_num_row counting table row $count=mysql_num_rows($result); // if result matched $myusername , $mypassword, table row must 1 row if($count==1){ // register $myusername, $mypassword , redirect file "login_success.php" header("location:login_success.php"); } else { echo "wrong username or password"; } ?>
the data not being submitted, error related trying access variable @ $_post['']
.
some simple error checking should fix it:
<?php [..] if ( isset( $_post['myusername'] ) && isset( $_post['mypassword'] ) ) { // username , password sent form $myusername=$_post['myusername']; $mypassword=$_post['mypassword']; [...] } ?>
Comments
Post a Comment