john666 Posted November 2, 2013 Share Posted November 2, 2013 I created all thing USING PHP and html but i can not Mention tht Error invalid user name and password with Red color Help me in that ..Thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 2, 2013 Share Posted November 2, 2013 (edited) What? Are you saying you have created a login form but you don't want the text in red to show? What is your current code? Edited November 2, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
john666 Posted November 3, 2013 Author Share Posted November 3, 2013 What? Are you saying you have created a login form but you don't want the text in red to show? What is your current code? <?php include('header.php'); include('config.php'); ?> <table class="login" align="center"> <tr> <td class="table1" > Student Information System</td> </tr> </table> <div class="table2"> <form method="post" > <table class="table3" align="center"> <tr><td>Username</td><td><input type="text" name="username"></td></tr> <tr><td>Password</td><td><input type="password" name="password"></td></tr> <tr><td colspan="2" align="center"><input type="submit" name="submit" value="LogIn"></td></tr> </table> </form> </div> <?php if (isset($_POST['submit'])) { $username=$_REQUEST['username']; $password=$_REQUEST['password']; $query="select *from login where user_name='$username' and pass_word='$password' limit 1"; $result=mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { header('location:stdrecord.php'); } else { $msg="Wrong Username Or Password"; header('location:index.php?'.$msg); } } ?> <?php include('footer.php'); ?> _________________________________________________ this is my Code i want to show that error mesg when user enter wrong username or password...... Error that is appeared in Red font Invalid username/Password what changing should i do in code??? Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted November 3, 2013 Solution Share Posted November 3, 2013 You are almost there. Process the user login before you display the login form. If the query didn't return any results then set the $msg variable to your error message. In the form check that this variable exists and then echo it. <?php include('header.php'); include('config.php'); if (isset($_POST['submit'])) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $query = "SELECT * FROM login WHERE user_name='$username' AND pass_word='$password' LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { header('location:stdrecord.php'); exit; } else { $error = "Wrong Username Or Password"; } } ?> <table class="login" align="center"> <tr> <td class="table1" > Student Information System</td> </tr> </table> <div class="table2"> <form method="post"> <table class="table3" align="center"> <?php if(isset($error)): ?> <tr> <td style="color: red; font-weight: bold"><?php echo $error; ?></td> </tr> <?php endif; ?> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="LogIn"></td> </tr> </table> </form> </div> <?php include('footer.php'); ?> When using using user input in SQL queries make sure you sanitize it using mysql_real_escape_string Quote Link to comment Share on other sites More sharing options...
john666 Posted November 3, 2013 Author Share Posted November 3, 2013 You are almost there. Process the user login before you display the login form. If the query didn't return any results then set the $msg variable to your error message. In the form check that this variable exists and then echo it. <?php include('header.php'); include('config.php'); if (isset($_POST['submit'])) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $query = "SELECT * FROM login WHERE user_name='$username' AND pass_word='$password' LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { header('location:stdrecord.php'); exit; } else { $error = "Wrong Username Or Password"; } } ?> <table class="login" align="center"> <tr> <td class="table1" > Student Information System</td> </tr> </table> <div class="table2"> <form method="post"> <table class="table3" align="center"> <?php if(isset($error)): ?> <tr> <td style="color: red; font-weight: bold"><?php echo $error; ?></td> </tr> <?php endif; ?> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="LogIn"></td> </tr> </table> </form> </div> <?php include('footer.php'); ?> When using using user input in SQL queries make sure you sanitize it using mysql_real_escape_string Thnx Brother u make My Day God Bless You Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.