php - Redirect to Index Page if the Submitted Form Has no Username or Password -
what wrong in code?
if(isset($_request["ok"])) { $id= mysql_real_escape_string($_request["usr"]); $pwd=mysql_real_escape_string($_request["pass"]); $row=mysql_query("select * tbl_login usr_id='$id' , password='$pwd'"); $data=mysql_fetch_array($row); if($pwd==$data["password"]) { $usr=mysql_query("select * tbl_usr u_id='".$data['u_id']."'"); $nm=mysql_fetch_array($usr); $_session["usr"]=$nm["u_fname"]; $_session["id"]=$nm["u_id"]; header("location:index.php"); } else { $msg="email or password not valid"; } }
and html code
<form method="post" enctype="multipart/form-data" > email-id<input type="text" name="usr" /> <br/> password<input type="password" name="pass"/> <input type="submit" value="login" name="ok" /> </form>
when user clicks on submit button without filling username , password, page should redirect index page.
in statement
if($pwd==$data["password"]) { $usr=mysql_query("select * tbl_usr u_id='".$data['u_id']."'"); $nm=mysql_fetch_array($usr); $_session["usr"]=$nm["u_fname"]; $_session["id"]=$nm["u_id"]; header("location:index.php"); }
since both $pwd
, $data["password"]
null, go inside if statement , redirect page index.php.
Comments
Post a Comment