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
https://forums.phpfreaks.com/topic/88798-select-query-problem/
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
https://forums.phpfreaks.com/topic/88798-select-query-problem/#findComment-454790
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.