supermerc Posted July 26, 2007 Share Posted July 26, 2007 Hey, I have my login script, and I added something to make it check if a few rows in the users table are empty and if they are the displays an alert box and redirects them somewhere and if they arnt empty it redirects them to the members page, but for some reason it doesnt see it as empty even if its empty. here is my code <?php $query = mysql_query("select account, pass, loginupdated from users where owname='".$_SESSION['s_username']."' LIMIT 1"); if (mysql_num_rows($query) != 1) { echo '<script type="text/javascript"> alert("Our records show us that you have yet to submit your account login, please do so now."); location = "setpass.php"; </script>'; } else { header("Location: members.php"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 bump Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 26, 2007 Share Posted July 26, 2007 Are you trying to see if account, pass, and loginupdated are empty in a row that already exists? If so, your method will not work. If a row exists with the owname set, even if those fields are empty, a result will still be returned, hence mysql_num_rows() == 1. You'll have to check if the fields are NULL or their default value, depending on how you've set up your table. Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 how do i do that? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 26, 2007 Share Posted July 26, 2007 Any number of ways -- try something like: <?php $query = "SELECT account IS NULL AND pass IS NULL AND loginupdated IS NULL AS incomplete FROM users WHERE owname='{$_SESSION['s_username']}' LIMIT 1"; $result = mysql_query($query) or die mysql_error(); if ($result && mysql_num_rows($result) && mysql_result($result,0) == 1): ?> <script type="text/javascript"> alert("Our records show us that you have yet to submit your account login, please do so now."); location = "setpass.php"; </script> <?php else header('Location: members.php'); endif; ?> Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 i get an error on $result = mysql_query($query) or die mysql_error(); Parse error: syntax error, unexpected T_STRING in /home/randomy/public_html/ed/acess.php on line 65 Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 26, 2007 Share Posted July 26, 2007 $result = mysql_query($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 26, 2007 Share Posted July 26, 2007 Right, what yarnold posted will fix that. Sorry, I've been programming some Perl lately; that must have carried over. Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 on line else header('Location: members.php'); Parse error: syntax error, unexpected T_STRING, expecting ':' in /home/randomy/public_html/ed/acess.php on line 74 Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 26, 2007 Share Posted July 26, 2007 <?php $query = "SELECT account IS NULL AND pass IS NULL AND loginupdated IS NULL AS incomplete FROM users WHERE owname='{$_SESSION['s_username']}' LIMIT 1"; $result = mysql_query($query) or die (mysql_error()); if ($result && mysql_num_rows($result) && mysql_result($result,0) == 1) { ?> <script type="text/javascript"> alert("Our records show us that you have yet to submit your account login, please do so now."); location = "setpass.php"; </script> <?php } else { header('Location: members.php'); } ?> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 26, 2007 Share Posted July 26, 2007 Or put a colon after else in the original. else: header('Location: members.php'); Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 26, 2007 Share Posted July 26, 2007 Or put a colon after else in the original. else: header('Location: members.php'); Apologies Wildbug, I'm not used to your syntax Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 Still not working it brings me to members.php even if its empty Quote Link to comment Share on other sites More sharing options...
dewey_witt Posted July 26, 2007 Share Posted July 26, 2007 Try this it may work. No guarantee's. I'd realy need to see the sign in HTML and the feilds in the database. $query = mysql_query("select account, pass, loginupdated from users where owname='".$_SESSION['s_username']."' LIMIT 1"); if (mysql_num_rows($query) < 1) { echo '<script type="text/javascript"> alert("Our records show us that you have yet to submit your account login, please do so now."); location = "setpass.php"; </script>'; } else { header("Location: members.php"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 27, 2007 Share Posted July 27, 2007 Or put a colon after else in the original. else: header('Location: members.php'); Apologies Wildbug, I'm not used to your syntax I like the alternative syntax when dropping in and out of PHP between code so I don't have to look for a single little curly brace hiding in that mess -- I can just look for an "endif;" or whatever. supermerc, Maybe it's time you described your SQL table. Will ALL of those fields be empty or just one or two of them? Are any of those fields defined NOT NULL? Quote Link to comment 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.