dare87 Posted August 24, 2007 Share Posted August 24, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/66562-solved-echo-errors/ Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 You're missing the braces around your else statement starting on line 149. Try: else{ foreach ($errors as $msg) echo " - $msg<br/>\n"; } You'll also need to add in something to show an error mesage if the user gets the captcha wrong. Quote Link to comment https://forums.phpfreaks.com/topic/66562-solved-echo-errors/#findComment-333401 Share on other sites More sharing options...
dare87 Posted August 24, 2007 Author Share Posted August 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66562-solved-echo-errors/#findComment-333428 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 replace if (empty($errors)) with if (count($errors) == 0) Quote Link to comment https://forums.phpfreaks.com/topic/66562-solved-echo-errors/#findComment-333438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.