surochek Posted July 11, 2007 Share Posted July 11, 2007 It only works if there's already a row in the table. Here's the little code that has me stuck: <?php session_start(); ob_start(); //connect with database include("connect.php"); $user=$_SESSION['username']; $sql = "SELECT * FROM traits WHERE username = '$user'"; $query = mysql_query($sql) or die (mysql_error(). " with query : ". $query."<br>"); $num=mysql_num_rows($query)or die (mysql_error(). " with query : ". $num."<br>"); if ($num<1){ header("Location: http://www.mashaholl.com/plotting/charactertraits_a.php"); } else{ header("Location: http://www.mashaholl.com/plotting/charactertraits_b.php"); } exit; ob_end_flush(); ?> If there are no rows that correspond to $user=$_SESSION['username'], I get this browser output: with query : 0 Which makes sense. But not. So why won't it redirect to the proper page? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 I would not do the or die on mysql_num_rows, not necessary. Basically check the data in the database for the username you are entering. Also I would use $sql instead of $query in the first or die portion. Give that a try and see what happens. I would also print out $user to make sure it is what you expected. Quote Link to comment Share on other sites More sharing options...
surochek Posted July 11, 2007 Author Share Posted July 11, 2007 Yes! That did it! Live and learn. Thanks! 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.