here is the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF (SELECT * FROM users WHERE firstname <> ‘’ AND email <> ‘’)"
and here is my code:
CODE
<?php
mysql_pconnect("$host","$user","$pass") or die (mysql_error());
mysql_select_db("$db") or die (mysql_error());
$name = $_POST['fname'];
$email = $_POST['email'];
$query = "INSERT INTO users (`firstname`, `email`) VALUES ('$fname', '$email') IF (SELECT * FROM users WHERE firstname <> '$name' AND email <> '$email', )";
//$query = "SELECT * FROM users WHERE firstname <> '$name' AND email <> '$email'"
//$query1 = "INSERT INTO users (`firstname`, `email`) VALUES ('$fname', '$email') IF email <> '$email'"
$result = mysql_query( $query ) or die (mysql_error());
//$result1 = mysql_query( $query1 ) or die (mysql_error());
$num = mysql_num_rows( $result );
if ($num == 1){
print "status=Same user&checklog=1";
} else {
print "status=New user&checklog=2";
}
?>
if i understand you right, you probably want to do something like this:
/* test if user exists */
$sql = "SELECT * FROM users WHERE email = '$email'";
$result = mysql_query( $sql );
/* if user does not exist */
if( mysql_num_rows($result) == 0 ) {
/* insert user into db */
$sql = "INSERT INTO users (firstname, email) VALUES ('$fname', '$email')";
$result = mysql_query( $sql ) or die('Could not add user');
}
cool thanks heaps bwh2…it only inserts the email into the database tho and not the name which is really odd?? because the sql code for the insert into line is all correct i’m sure of it and the fields and what not are all correct to… can you think of anything??