-4

I fill the login form and click on submit button and page is reloaded and email id is blank how to get email id text filled?
This is the php code.

<?php 
if(isset($_POST["btnSubmit"]))
{   
if($_POST["txtEmail"]=="")
{
    $errormsg = "Please enter Email.";

}
else if($_POST["txtPassword"]=="")
{
    $errormsg = "Please enter Password.";
}

else
{

    $Email =  $_POST["txtEmail"];

    $Password =  md5($_POST["txtPassword"]);

    $info = mysql_query("select * from tbluser where Email ='$Email' and Password='$Password'");

    $count_info=mysql_num_rows($info);

    if($count_info>0)
    {
            while($a = mysql_fetch_array($info))
            {
                $b = strcmp($a["Email"],$Email);

                if($b==0 && $a["Password"]=="$Password" && $a["IsVisible"]==1)
                {   
                    $_SESSION["UserId"] = $a["user_id"];
                    $_SESSION["UserName"] = $a["user_name"];
                    header("Location:index.php");
                }
                else
                {
                    $errormsg="Register Your Account First.";
                }
            }
    }
    else
    {
        $errormsg="Invalid email or password.";
    }

}

}
?>

end of php code.

Starting of form tag.

<form name="login" method="post">
          <table id="form">

            <tr>
                <td>
                    <?php
                        if($errormsg!="")
                        {
                    ?>
                            <span id="errorPassword" style="padding-left:10px; color:#C00;"> <?php echo $errormsg; ?> </span>
                    <?php
                        }
                    ?>
                </td>
            </tr>

            <tr>
                <td style="width:200px;">Email: <span style="color:#F00">*</span></td>
                <td style="width:300px;"><input type="text" id="txtEmail" name="txtEmail" placeholder="Email" /></td>
                <td style="width:200px;"></td>
            </tr>

            <tr>
                <td>Password: <span style="color:#F00">*</span></td>
                <td><input type="text" id="txtPassword" name="txtPassword" placeholder="Password" /></td>
                <td><span id="errorEmail" style="padding-left:10px; color:#C00;"></span></td>
            </tr>



            <tr>
                <td></td>
                <td align="left" ><input type="submit" id="form_button" name="btnSubmit" value="Join Now"/></td>
            </tr>
        </table> 
        </form>

Ending of form tag.

4

2 回答 2

1

PHP Part

<?php
$Email=''; //added here so the email is not confined to the else block (better practice to initilize).<------
if(isset($_POST["txtEmail"])){$Email =  $_POST["txtEmail"];} // this will ensure that even if you have not typed in the password the email still shows up.
if(isset($_POST["btnSubmit"]))
{   
if($_POST["txtEmail"]=="")
//rest of your code

in html part

<input type="text" id="txtEmail" name="txtEmail" placeholder="Email" value="<?php echo htmlspecialchars($Email);?>" />
                                                                          // ^^ added here 

You can post back any value like this.

于 2013-09-02T07:43:52.250 回答
0

I think you are looking for something like:

<input type="text" id="txtEmail" name="txtEmail" placeholder="Email" value="<?php if(isset($Email)){echo $Email;} ?>" />
<!-- you might/want to escape $Email with something like htmlspecialchars -->
于 2013-09-02T07:38:49.893 回答