Jump to content

select query problem


affordit

Recommended Posts

I am wanting to use the below code to check table to find out if name OR email address already exists but I get an error. Says syntax error near

 

FROM test Where name = '$name' || email = '$email'";

 

Here is all of the code:

 

$query = "Select name, email, from test Where name = '$name' || email = '$email'";

$results = mysql_query($query) or die(mysql_error()."<br /><br />".$query);

$num=mysql_numrows($results);

if ($name == name) {

print "Name exists";

exit();

}elseif

($email == email){

print "Email exists";

exit();

Link to comment
Share on other sites

This might be useful, it's a checkunique function I use

 

function checkUnique($table, $field, $compared){
if (get_magic_quotes_gpc()) {
$table = stripslashes($table);
$field = stripslashes($field);
$compared = stripslashes($compared);
}
$table = mysql_real_escape_string($table);
$field = mysql_real_escape_string($field);
$compared = mysql_real_escape_string($compared);

$result = mysql_query("SELECT $field FROM $table WHERE $field = '$compared'");
if(mysql_num_rows($result)==0) {
return TRUE;
}
else {
return FALSE;
}
}

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.