Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Struggling with MYSQL syntax

    I am trying to get through some code and just struggling. Any help would be appreciated.

    Code:
    /* 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

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    "AND

    should be

    " AND

    You are missing the space that separates it from the preceding variable.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still not working

    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

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Location
    United States
    Posts
    157
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Is wp_user and wp_usermeta suppose to be a variable that has the tablename, or is that the actual table?

    PHP Code:
    $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."`
    PHP Code:
    $sql "SELECT user_id FROM wp_user WHERE last_name = '$last_name' AND first_name = '$first_name'"
    Last edited by votter; 12-07-2011 at 04:33 PM.
    Adobe Dreamweaver shall be destroyed!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •