Jump to content

[SOLVED] echo errors


dare87

Recommended Posts

I add a captcha to my login but now my errors are not showing up. also it I add the captcha error it is there when the page loads... Any help would be great... Thanks

 

The system does work... you just don't get errors printed if you don't put a user name in or a password or if the captcha code was wrong

Thanks

<?php
// Include the PHP script that contains the session information.
include('includes/session.php');

// Start output buffering. This will allow me to set my headers at a later point in the script.
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The Date Tiki - Your Dating Resource</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="includes/base.css" title="Default" media="screen" />
<script type="text/javascript" src="includes/include.js"></script>
<script type="text/javascript">
   window.onload = formFocus;
</script>
</head>

<body>
<script language="JavaScript"><!--
ts = <?= $ts ?>;
--></script>
<?php include('includes/top.php'); ?>
<div id="main">

	<div id="sideBarLeft"><?php include('includes/left.php'); ?></div>

	<div id="content">
		<div class="innerContent">
			<form name="Login" action="login.php" method="post">
				<table align="center" width="100%" border="0" cellpadding="1" cellspacing="0">
				<tr>
					<td class="title" colspan="2">Account Login</td>
				</tr>
				<tr>
					<td class="smallText" colspan="2">Don't have one <a href="register.php">register here.</a> Its FREE!</td>
				</tr>
				<tr>
					<td>User Name:</td>
					<td><input type="text" class="required" name="userName" id="focus" size="40" value="<?php echo $userName ?>" maxlength="200"></td>
				</tr>
				<tr>
					<td>Password:</td>
					<td><input type="password" class="required" name="password" size="40" value="<?php echo $password ?>" maxlength="40"></td>
				</tr>
				<tr>
					<td>Security Code:</td>
					<td>
						<!-- pass a session id to the query string of the script to prevent ie caching -->
						<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
						<input type="text" class="required" name="code" />
					</td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" class="button" name="submit" value="Submit"></td>
				</tr>
				<tr>
					<td class="smallText" colspan="2">* Highlighted forms designate required fields.</td>
				</tr>
				<tr>
					<td class="smallText" colspan="2">Did you forget your Password? <a href="forgot_password.php">Reset it here.</a></td>
				</tr>
				</table>
			</form>
			<?php
			if (isset($_POST['submit'])) // The form has been submitted.
			{
				// Initialize an error array to contain any error messages.
				$errors = array();

				include("securimage.php");
				  $img = new Securimage();
				  $valid = $img->check($_POST['code']);

				  if($valid == true) {

				// Check for a user name.
				if (!empty($_REQUEST['userName']))
					$userName = $_REQUEST['userName'];
				else
					$errors[] = 'Please enter your user name.';

				// Check for a password.
				if (!empty($_REQUEST['password']))
					$password = $_REQUEST['password'];
				else
					$errors[] = 'Please enter your password.';

				// If the user entered their information, validate it.
				if (empty($errors))
				{
					require_once ('../../datemysql_connect.php');

					$query = "SELECT user_id, first_name, last_name, user_name, access_level, email FROM users WHERE user_name='$userName' AND password=SHA('$password') AND active IS NULL";
					$results = @mysql_query($query);

					$row = mysql_fetch_array($results, MYSQL_NUM);

					// If a match was found.
					if ($row)
					{
						$_SESSION['userId'] = $row[0];
						$_SESSION['firstName'] = $row[1];
						$_SESSION['lastName'] = $row[2];
						$_SESSION['userName'] = $row[3];
						$_SESSION['accessLevel'] = $row[4];
						$_SESSION['email'] = $row[5];

						// Delete the output buffer.
						ob_end_clean();

						// Redirect the user to the correct page.
						if ($row[4] == 0) // Administrator
						{
							$url = 'link.php';
							header("Location: $url");
						}
						else if ($row[4] == 1) // Editor
						{
							$url = 'admin_notes.php';
							header("Location: $url");
						}
						else if ($row[4] == 2) // Contributor
						{
							$url = 'admin_notes.php';
							header("Location: $url");
						}
						else if ($row[4] == 3) // Correspondent
						{
							$url = 'admin_notes.php';
							header("Location: $url");
						}
						else if ($row[4] == 4) // Team Member
						{
							$url = 'blog.php';
							header("Location: $url");
						}
						else if ($row[4] == 5) // Other
						{
							$url = 'blog.php';
							header("Location: $url");
						}
					}
					else
						echo ' No record was found matching your username and password.';
				}
				else
					foreach ($errors as $msg)
						echo " - $msg<br/>\n";
			}
		}
			?>
		</div>
		<div id="footer"><?php include('includes/bottom.php'); ?></div>
	</div>



</div>

</body>
</html>

Link to comment
Share on other sites

adding the braces didn't fix the problem.. and if I put the error for the captcha on there.. it shows up when the page is first loaded and you have not even hit submit yet.

 

new code

 

<?php //rest of code in first post

else {
					foreach ($errors as $msg)
						echo " - $msg<br/>\n";
					}
			}
		} else echo ' Security Code did not match!' 

?>

 

Thanks... any other help would be great

Link to comment
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.