liquid79 Posted November 12, 2007 Share Posted November 12, 2007 My code is below, the problem is if it finds the username in the datbase it displays the message fine, but if it doesnt find it it just shows a blank white page they dont move on to the else statment. Im not sure what im doing wrong. Any Help would be great trying to make it work for a few days now with not much luck. Thanks! <?php require_once ('settings.php'); checkLogin('1 2'); session_start(); if ($_SESSION['logged_in']): $username1 = get_username($_SESSION['user_id']); $sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'"); while ($row = mysql_fetch_object($sql)) { // Check to see if there is a match of details and display yes, no or Contact an admin! when $completed is called. if ($row->username == $username1) { echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the <em><a href="update_property.php" class="white_link"> Update details link</a></em> to make changes. Thankyou</h2> </font>'; // Error Message If it finds the username in the database } else { echo ' <font color="#FF2A2A">Welcome you can carry on <p> All details etc here</font>'; // if it finds no details it will allow the person to carry on. } } endif; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 12, 2007 Share Posted November 12, 2007 Endif? Are you using PHP 3.0? If you're using PHP 4+, use {} around your first IF statement. Also, you may want to start your session first before your require. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 12, 2007 Share Posted November 12, 2007 before the whlie run a check to say if(mysql_num_rows($result) >0) it tends to error if you don't check first and it returns a 0 set Quote Link to comment Share on other sites More sharing options...
liquid79 Posted November 12, 2007 Author Share Posted November 12, 2007 ok thanks guys im still only learning PHP but getting there slowly! Is it possible you could give me an example where the {} should go on my first if statement? ( i have removed the endif) I have added the if (mysql_num_rows($sql) > 0); after my sql query as suggested but should i now echo something also to check it ? My code now: <?php session_start(); require_once ('settings.php'); $username1 = get_username($_SESSION['user_id']); $sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'"); if (mysql_num_rows($sql) > 0); while ($row = mysql_fetch_object($sql)) { // Check to see if there is a match of details with the session username and display which is the case. if ($row->username == $username1) { echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the Update details link to make changes.</h2> </font>'; // Error Message If it finds the username in the database } else { echo ' <font color="#FF2A2A">Welcome you can carry on '; // if it finds no details it will allow the person to carry on. } } ?> Thanks again! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 12, 2007 Share Posted November 12, 2007 try <?php session_start(); require_once ('settings.php'); $username1 = get_username($_SESSION['user_id']); $sql = mysql_query("SELECT * FROM details_temp2 WHERE username = '$username1'"); if (mysql_num_rows($sql) > 0){ while ($row = mysql_fetch_object($sql)) { // Check to see if there is a match of details with the session username and display which is the case. if ($row->username == $username1) { echo '<font color="#FF2A2A"><h2>ERROR: You have already Sumbited your details please use the Update details link to make changes.</h2> </font>'; // Error Message If it finds the username in the database } else { echo ' <font color="#FF2A2A">Welcome you can carry on '; // if it finds no details it will allow the person to carry on. } } } else{ echo "No results Found."; } ?> Make sense? Quote Link to comment Share on other sites More sharing options...
liquid79 Posted November 12, 2007 Author Share Posted November 12, 2007 Yep thats great, Thanks now i have read through what you have done i can see the light! Thanks for the great reponse! 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.