chris_s_22 Posted January 10, 2009 Share Posted January 10, 2009 this is part of my login i want to add a query that checks the registered feild if 1 allow to login anything else to be refused im guessing it gonna be somthing like this $query = "select registered from user where username='$username' limit 1"; $result = mysql_query($query); this is my login function how/where do i add the query above obviously i need the proper finished query function user_login($username, $password) { // Try and get the salt from the database using the username $query = "select salt from user where username='$username' limit 1"; $result = mysql_query($query); $user = mysql_fetch_array($result); // Using the salt, encrypt the given password to see if it // matches the one in the database $encrypted_pass = md5(md5($password).$user['salt']); // Try and get the user using the username & encrypted pass $query = "select userid, username from user where username='$username' and password='$encrypted_pass'"; $result = mysql_query($query); $user = mysql_fetch_array($result); $numrows = mysql_num_rows($result); // Now encrypt the data to be stored in the session $encrypted_id = md5($user['userid']); $encrypted_name = md5($user['username']); // Store the data in the session $_SESSION['userid'] = $userid; $_SESSION['username'] = $username; $_SESSION['encrypted_id'] = $encrypted_id; $_SESSION['encrypted_name'] = $encrypted_name; if ($numrows == 1) { return 'Correct'; } else { return false; } } Link to comment https://forums.phpfreaks.com/topic/140316-query/ Share on other sites More sharing options...
ngreenwood6 Posted January 10, 2009 Share Posted January 10, 2009 Can you explain what you are trying to do again because your post is a little confusing? Link to comment https://forums.phpfreaks.com/topic/140316-query/#findComment-734254 Share on other sites More sharing options...
chris_s_22 Posted January 10, 2009 Author Share Posted January 10, 2009 what i want is when people login i want to check that people are registered if they are registered to alow them access otherwise deny them. i have already do this when people sign up they are sent a email with a link which they have to click on the link which sets the registered feild to 1 Link to comment https://forums.phpfreaks.com/topic/140316-query/#findComment-734266 Share on other sites More sharing options...
ngreenwood6 Posted January 10, 2009 Share Posted January 10, 2009 oh you would need a simple query like this: $query = "SELECT * FROM table WHERE username= '$username'"; $results = mysql_query($query); //then do something like this while($row = mysql_fetch_array($results)) { if($row['registered'] == 1) //if they are registered { do this } else { do this } } Link to comment https://forums.phpfreaks.com/topic/140316-query/#findComment-734270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.