Forum Moderators: coopster
<?php
$errmsg = "";
$complete = true;
if (isset($_POST['submit'])) {
$fname = ($_POST['firstname']);
$lname = ($_POST['lastname']);
if (empty($_POST[fname])) {
$errmsg = "Plese provide your FirstName";
$fname = "";
$complete = false;
}
if (empty($_POST[lname])) {
$errmsg = "Plese provide your LastName";
$fname = "";
$complete = false;
}
if ($complete == true) {
echo "<script>document.location.href='fine.html'</script>";
exit();
}
}
else
{
echo $errmsg;
}
?>
Try something like this:
[pre]
<?php
if (isset($_POST['submit']) &&!empty($_POST['fname']) &&!empty($_POST['lname'])) {
header('Location: fine.html');
exit();
} else {
echo 'You must fill out every field in the form!';
}
?>
[/pre] Although it doesn't show a specific error message, I think it serves your purpose just as well ;)
Good luck!
P.S. What was wrong with your code was that the if conditional evaluated to TRUE, so the else never got called therefore not echoing out your error message.
if (mysql_numrows($check)>0)
{
//redirect to member home page
header('Location:http://www.domain.org/page.htm');
exit;
}
else
{
echo "Invalid username and password found";
}
I am trying to redirect to a page that was built with FP. Does that make a difference?
if (mysql_numrows($check)>0)
To this:
if ([url=http://us3.php.net/manual/en/function.mysql-num-rows.php]mysql_num_rows[/url]($check)>0)
Watch those spelling errors ;)
Also, make sure that no content is being outputted to the browser before your header() call.
Good luck!
P.S. for future debugging, put error_reporting [us3.php.net](E_ALL); at the top of your script.
Warning: Cannot modify header information - headers already sent by (output started at /homepages/34/d175731624/htdocs/login.php:8) in /homepages/34/d175731624/htdocs/login.php on line 101
Is there another function that I should be using to redirect my page to another page?
<!--#######################################login Information#################################################-->
<?PHP
if(!isset($_COOKIE["user"]))
{
echo '
<div id="loginInformation">
<form method="post">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="loginUserID" style="width:100px; height:20px; vertical-align:middle; font-size:12px; ">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="loginPassword" style="width:100px; height:20px; vertical-align:middle; font-size:12px;">
</td>
</tr>
<tr>
<td>
<input type="submit" name="login" value="Login">
</td>
</tr>
</table>
</form>
</div>';
}
?>
<!--#######################################End Login Information#############################################-->
<?php
error_reporting(E_ALL);
if(isset($_POST['login']))
{
//connect to database
if ($link = mysql_connect("localhost", "#*$!", "#*$!"))
{
// select the database that will be used
mysql_select_db("#*$!") or die("An error has ocurred. Please contact the site administrator.");
//set post variables
$username = $_POST['loginUserID'];
$password = $_POST['loginPassword'];
// makes sure fields are completed
if(!$_POST['loginUserID'] ¦!$_POST['loginPassword'])
{
echo "Please enter the username and/or password";
die(" - Try again");
}
$check = mysql_query("SELECT * FROM members WHERE username = '$username' and passwd = '$password'");
//Gives error if user dosent exist
if (mysql_num_rows($check)>0)
{
header('Location:members_attorneys.htm');
exit;
}
else
{
echo "Invalid username and password found";
}
}
else
{
echo "No connection made to database";
}
}
?>
I'm still new to this PHP stuff, but things are beginning to make more sense.
If you have any suggestions on what function I should be using, thanks for any input.
I just added the form post to my current html page and the login code for test the username and password in the php file. It works great and now I just a little bit clearer understanding of how php executes and processes information.
Thanks
$username = [url=http://us2.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($_POST['loginUserID']);
$password = mysql_real_escape_string($_POST['loginPassword']);
Also make sure to validate that the user successully logged in when they visit other pages that require login.
Good luck!