merylvingien Posted February 16, 2011 Share Posted February 16, 2011 What the hell am i missing here?? Trying to set the $output so if there are any errors it will display a message. If no email or password is entered the $output is echoed fine But if the wrong email or password is entered the $ouptut is not echoed at all??? if (loggedin()){ header ("Location: index.php"); exit(); } if (isset ($_POST['login'])) { $email= $_POST['email']; $password= $_POST['password']; if (isset ($_POST['rememberme'])) {$rememberme= $_POST['rememberme'];} if (isset($rememberme)) {$rememberme= "on";} else {$rememberme= "off";} if (empty($email)) {$output= "<span class='error'>Please enter a username or password</span>";} if (empty($password)) {$output= "<span class='error'>Please enter a username or password</span>";} if ($email&&$password) { $login= mysql_query ("SELECT * FROM user WHERE email='$email'"); while ($row= mysql_fetch_assoc($login)) { $passwordcheck = $row['password']; if (md5($password)==$passwordcheck) $loginok = true; else $loginok = false; if ($loginok==true) { $uniquelogon = "{$row['uniqlogon1']}"; if ($rememberme=="on"){ setcookie("uniquelogon", $uniquelogon, time()+2628000);} else if ($rememberme=="off"){ session_start(); $_SESSION['uniquelogon'] = "$uniquelogon";} header ("Location: index.php"); exit(); } else echo "<span class='error'>Your Email or Password do not match our records</span>"; } } } <?php if (!empty($output)) {echo $output;} ?> <form action"login.php" method="POST"> <p>Email:<br> <input type="text" name="email"> </p> <p>Password:<br> <input id="pwd" type="password" class="required lock pad" watermark="{html:'Password',cls:'pad empty'}" name="password"> </p> <p> <input type="checkbox" name="rememberme"> Remember Me!<br> </p> <input type="submit" name="login" value="Log In"> </form> Ive used all my special powers trying to get this to work, but i am missing something... Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/ Share on other sites More sharing options...
AbraCadaver Posted February 16, 2011 Share Posted February 16, 2011 Maybe instead of: echo "<span class='error'>Your Email or Password do not match our records</span>"; You want: $output = "<span class='error'>Your Email or Password do not match our records</span>"; Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175087 Share on other sites More sharing options...
merylvingien Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks for the reply, but ive tried that already, nothing i do will work! Zilch! Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175100 Share on other sites More sharing options...
BlueSkyIS Posted February 16, 2011 Share Posted February 16, 2011 if the wrong email or password is entered, $output is not set. you'll need to define $output somewhere before trying to echo it. i suggest that you indent your code so the logic is more apparent. Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175122 Share on other sites More sharing options...
merylvingien Posted February 16, 2011 Author Share Posted February 16, 2011 if ($rememberme=="off"){ session_start(); $_SESSION['uniquelogon'] = "$uniquelogon";} header ("Location: index.php"); exit(); } else $output= '<span class="error">argh</span>'; } } } Like that you mean? which is what AbraCadaver suggested, which i have already tried. Ive tried all sorts of different combinations but nothing i do will display! I cant understand where i am going wrong here. Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175127 Share on other sites More sharing options...
BlueSkyIS Posted February 16, 2011 Share Posted February 16, 2011 i suggest that you indent your code so the logic is more apparent. Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175173 Share on other sites More sharing options...
merylvingien Posted February 16, 2011 Author Share Posted February 16, 2011 Sorted it!!! Had to change the way that some other variables were defined which i still dont quite understand. But hey ho. Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175191 Share on other sites More sharing options...
silkfire Posted February 16, 2011 Share Posted February 16, 2011 It's because you use empty() instead of isset(). Empty() gives true for an empty string, even if it exists. Quote Link to comment https://forums.phpfreaks.com/topic/227888-defining-a-variable/#findComment-1175219 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.