Jump to content

MySQL


shank888

Recommended Posts

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.";
      }

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.