Here is my login PHP code.
<?php // rnlogin.php
include_once 'rnheader.php';
echo "<h3>Member Log in</h3>";
$error = $user = $pass = "";
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
{
$error = "Not all fields were entered<br />";
}
else
{
$query = "SELECT user,pass FROM rnmembers
WHERE user='$user' AND pass='$pass'";
if (mysql_num_rows(queryMysql($query)) == 0)
{
$error = "Username/Password invalid<br />";
}
else
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
die("You are now logged in. Please
<a href='rnmembers.php?view=$user'>click here</a>.");
}
}
}
echo <<<_END
<form method='post' action='rnlogin.php'>$error
Username <input type='text' maxlength='16' name='user'
value='$user' /><br />
Password <input type='password' maxlength='16' name='pass'
value='$pass' /><br />
<input type='submit' value='Login' />
</form>
_END;
?>
As you can see the error message is printed with echo.
Is there a way that I can put this error message in a control and display it only if there is error?
It sounds like I have to combine PHP with JavaScript?
The following code is used by Gmail to display error message.
It works even if JavaScript is turned off.
In other words, they use some techniques independent of JS.
Any idea, how I can do similar thing here?
<code>
<td align="left">
<div id="errormsg_0_Passwd" class="errormsg">
The username or password you entered is incorrect.
[<a target="_blank" name="helpLink" href="http://www.google.com/support/accounts/bin/answer.py?answer=27444&hl=en&ctx=ch_ServiceLoginAuth&p=mail">?</a>]
</div>
</td>
</code>
Thank you
in PHP you can do anything. Want to put this error message in a control? Put it into control
You have to distinguish string operation from echoing.
echoing a string is not the only way of string manipulations.
you can prepare your string first and then echo it out.
So, you can prepare all parts of the string first, and then print them all together.
Also, there is another way to output HTML, a preferred one.