matvespa Posted December 27, 2009 Share Posted December 27, 2009 I've found this code online, and cant seem to make it work against my database. It kept saying, user is available even though the user exist in the database. UserAvailability.php: <?php //I've declared the variable according to my database. mysql_connect($host, $db_username, $db_password) or die ("Can't connect to Datebase"); mysql_select_db($db_name) or die ("Couldn't successfully connected"); $username=$_POST['username']; $query=("Select * from user where UserEmail='$username'"); $result= mysql_query($query); $num=mysql_num_rows($result); if ($num > 0) {//Username already exist echo "no"; }else{ echo "yes"; } ?> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 27, 2009 Share Posted December 27, 2009 I've found this code online, and cant seem to make it work against my database. It kept saying, user is available even though the user exist in the database. UserAvailability.php: <?php //I've declared the variable according to my database. mysql_connect($host, $db_username, $db_password) or die ("Can't connect to Datebase"); mysql_select_db($db_name) or die ("Couldn't successfully connected"); $username=$_POST['username']; $query=("Select * from user where UserEmail='$username'"); $result= mysql_query($query); $num=mysql_num_rows($result); if ($num > 0) {//Username already exist echo "no"; }else{ echo "yes"; } ?> Maybe you should check the session to see if they are online? It should be very simple to enter an entry into their row 'availability' if you don't just want to use sessions to mark availability on a page. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2009 Share Posted December 27, 2009 You are checking if the entered $username is equal to values in a column named UserEmail - where UserEmail='$username' Does your UserEmail column actually contain user names? Quote Link to comment Share on other sites More sharing options...
matvespa Posted December 27, 2009 Author Share Posted December 27, 2009 The variable username = useremail Btw how do i check is the session is online? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 27, 2009 Share Posted December 27, 2009 The variable username = useremail Btw how do i check is the session is online? I assume you've a session to turn on as they log in (?) if (isset($_SESSION['username'])) { //sql statement to tell they're online, aka available } else { //erase the entry where user is online } Not sure if this is the best way of coming along it though.. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2009 Share Posted December 27, 2009 Is your code echoing 'no' or 'yes'? It will echo 'no' if the username (useremail) that was entered was found in your table. It will echo 'yes' if the username was not found and also if your query failed. To help debug if your query worked or failed in the code you are trying, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Edit: Also, echo $query to see exactly what is in it so that you know your form is submitting the expected data. 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.