shank888 Posted December 20, 2011 Share Posted December 20, 2011 I have the code snippet below trying to check my database if a variable exists, it seems to work for the username but not for the email. The database name is "communitycouch_users" table is "reg_vars" to check the row: email. the variable $email is coming from my form. Upon form submission it will submit the data into the database regardless it exists. $email= $_POST['email']; $username= $_POST['username']; // Check if the email and username exist already if(MysqlVarExists("communitycouch_users", "reg_vars", "email", $email) == true) { $errors_code["existing_email"] = "That email is already being used."; } if(MysqlVarExists("communitycouch_users", "reg_vars", "username", $username) == true) { $error_code["existing_username"] = "That username is already in use."; } Quote Link to comment https://forums.phpfreaks.com/topic/253517-mysql/ Share on other sites More sharing options...
trq Posted December 20, 2011 Share Posted December 20, 2011 You should be doing this check in your query. Whatever MysqlVarExists() does, it does it wrong. $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $sql = "SELECT id FROM tbl WHERE email = '$email' && username = '$username';"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // record found } else { // username or email not found } } else { // query failed } Quote Link to comment https://forums.phpfreaks.com/topic/253517-mysql/#findComment-1299671 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.