Jump to content

Need Help Little


Go to solution Solved by Ch0cu3r,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.