...

View Full Version : Struggling with MYSQL syntax



saltschuler
12-07-2011, 01:43 AM
I am trying to get through some code and just struggling. Any help would be appreciated.



/* Step 2. Get ID of member to update */

$sql= "SELECT user_id FROM" . wp_user
. "WHERE last_name = "
. $last_name . "AND first_name = "
. $first_name;
$uid = mysql_query($sql) or die(mysql_error());
echo "<hr>DEBUG SQL: " . $sql . "<hr>\/n";
/* Update the expiration date */

$sql = "UPDATE" . wp_usermeta
. "SET exp_date = "
. $expdate
. "WHERE user_id ="
. $uid . "AND meta_key = 'exp_date'";
$result = mysql_query($sql) or die(mysql_error());


Thanks

felgall
12-07-2011, 02:23 AM
"AND

should be

" AND

You are missing the space that separates it from the preceding variable.

saltschuler
12-07-2011, 02:48 PM
I tried that fix and get the following 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 'last_name = AND first_name =' at line 1

votter
12-07-2011, 05:30 PM
Is wp_user and wp_usermeta suppose to be a variable that has the tablename, or is that the actual table?



$sql= "SELECT user_id FROM" . wp_user
. "WHERE last_name = "
. $last_name . "AND first_name = "
. $first_name;
$uid = mysql_query($sql) or die(mysql_error());

should be something like below if it is the actual table. If not then adjust it to a variable like: `".$wp_user."`


$sql = "SELECT user_id FROM wp_user WHERE last_name = '$last_name' AND first_name = '$first_name'";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum