dannyone Posted March 23, 2009 Share Posted March 23, 2009 hello, im wondering if there is a way to do this. i have a page where users can select from a few drop downs some values and save them into a db. is there a way to create a query were if the user exists in the db then they can not use that page? im storing the user_id in a session. any help would be greatly appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/150745-if-exists-kick-out/ Share on other sites More sharing options...
Maq Posted March 23, 2009 Share Posted March 23, 2009 is there a way to create a query were if the user exists in the db then they can not use that page? Yeah just do a query to return some amount of rows with that user and if it returns rows don't let me insert... session_start(); $user = $_SESSION['user']; $result = myql_query("SELECT * FROM table WHERE user = '$user'") or die(mysql_error()); if(mysql_num_rows($result) > 0) { echo "sorry, you're already in the DB"; } else { echo "not in the DB, do whatever you want in this block"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150745-if-exists-kick-out/#findComment-791961 Share on other sites More sharing options...
dannyone Posted March 23, 2009 Author Share Posted March 23, 2009 thanks for the reply Maq, i have tried using your code and modifying to match my data but it doesn't seem to work it just gives me a blank page. do i need to add more detail into it to get it to work? <?php $user = $_SESSION['login']; mysql_connect("localhost", "xx", "xx") or die(mysql_error()); mysql_select_db("xx") or die(mysql_error()); $result = myql_query("SELECT * FROM Marker_Rooms WHERE Marker_ID = '$user'") or die(mysql_error()); if(mysql_num_rows($result) > 0) { echo "sorry, you're already in the DB"; } else { echo "not in the DB, do whatever you want in this block"; } ?> im already calling session further up so not included it here thanks Quote Link to comment https://forums.phpfreaks.com/topic/150745-if-exists-kick-out/#findComment-792005 Share on other sites More sharing options...
Maq Posted March 23, 2009 Share Posted March 23, 2009 $result = myql_query Should be (missing the 's' in sql): $result = mysql_query -You need session_start(); at the top of your page, also add in error reporting and tell me if there is any output. session_start(); ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/150745-if-exists-kick-out/#findComment-792008 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.