Jump to content

Need Help Little


john666

Recommended Posts

:confused: 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???

Link to comment
https://forums.phpfreaks.com/topic/283533-need-help-little/#findComment-1456665
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/283533-need-help-little/#findComment-1456686
Share on other sites

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 :D God Bless You

Link to comment
https://forums.phpfreaks.com/topic/283533-need-help-little/#findComment-1456690
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.