• I am converting SQL to $wpdb. I get this error: `WordPress database error: [Unknown column ‘0’ in ‘where clause’]
    UPDATE AAUW_Members SET ID = 202205, Title = ‘Dr.’, FirstName = ‘Grace’, LastName = ‘Hopper’, Address1 = ‘3114 Rittenhouse’, City = ‘Washington’, State = ‘DC’, Zip = ‘10225’, HomePhone = ‘845-236-7971’, CellPhone = ‘845-236-5555’, Email = ‘[email protected]’, College1 = ‘USNA’, College2 = ‘Cornell’, College3 = ‘Stanford’, Birth_Day = ‘5’, Birth_Month = ‘Feb’, Mem_Type = ‘MOB’, Honorary = ‘0’, Joined_Local = ‘3/22/2022’, Joined_Natl = ‘3/22/2022’, Mailings = ‘Email’, Positions_Held = ‘Developer’, Notes = ‘Math Program for longrange artillery’, Referred = ‘Howard Aiken’, Retired = ‘Y’, Employer = ‘USNA’, Occupation = ‘Cobol developer’, Positions = ‘taught at Vassar’, OtherWriteIn = ‘Lecturer, Mentor’ WHERE 0 = ‘%d’ AND 1 = ‘%s’ AND 2 = ‘%s’ AND 3 = ‘%s’ AND 4 = ‘%s’ AND 5 = ‘%s’ AND 6 = ‘%s’ AND 7 = ‘%s’ AND 8 = ‘%s’ AND 9 = ‘%s’ AND 10 = ‘%s’ AND 11 = ‘%s’ AND 12 = ‘%s’ AND 13 = ‘%s’ AND 14 = ‘%s’ AND 15 = ‘%s’ AND 16 = ‘%s’ AND 17 = ‘%s’ AND 18 = ‘%s’ AND 19 = ‘%s’ AND 20 = ‘%s’ AND 21 = ‘%s’ AND 22 = ‘%s’ AND 23 = ‘%s’ AND 24 = ‘%s’ AND 25 = ‘%s’ AND 26 = ‘%s’ AND 27 = ‘%s’ AND 28 = ‘%s’`
    ID is an integer.

    $result_check = $wpdb->UPDATE('AAUW_Members', 
        array(
       	'ID' => $ID,      
    	'Title' => $Title,
       	'FirstName' => $FirstName,
    	'LastName'=> $LastName,
    	'Address1'=> $Address1,
    	'City'=> $City,
    	'State'=> $State,
    	'Zip'=> $Zip,
    	'HomePhone'=> $HomePhone,
    	'CellPhone'=> $CellPhone,
    	'Email'=> $Email,
    	'College1'=> $College1,
    	'College2'=> $College2,
    	'College3'=> $College3,
    	'Birth_Day'=>$Birth_Day,
    	'Birth_Month'=>$Birth_Month,
    	'Mem_Type' =>$Mem_Type,
    	'Honorary' =>$Honorary,
    	'Joined_Local'=>$Joined_Local,
    	'Joined_Natl' =>$Joined_Natl,
    	'Mailings' =>$Mailings,
    	'Positions_Held'=>$Positions_Held,
    	'Notes'=>$Notes,
    	'Referred'=>$Referred,
    	'Retired'=>$Retired,
    	'Employer'=>$Employer,
    	'Occupation'=>$Occupation,
    	'Positions'=>$Positions,
    	'OtherWriteIn'=>$OtherWriteIn
    
    	
        ),
        array(
    	 '%d',
       	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s',
    	 '%s'
    	 
        ) 
      ); 
    	
    • This topic was modified 2 years, 6 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Where are you getting this SQL? You say you’re converting it… ” WHERE 0 = ‘%d’ ”

    Is this a table you’ve created?

    Thread Starter hsysgrp

    (@hsysgrp)

    Hi Steve, thank you. the SQL is from a working custom page used to update member data on a WordPress website. The tablename is AAUW_Members. The error dump I posted complains about unknown column ‘0’. But column 0 is ‘ID’=>$ID which is matched with ‘%d%’ because ID is an integer. `$sql = “UPDATE AAUW_Members SET ID = ‘$ID’, Title = ‘$Title’, FirstName = ‘$FirstName’, LastName = ‘$LastName’, Address1 = ‘$Address1’, City = ‘$City’, State = ‘$State’, Zip = ‘$Zip’, HomePhone = ‘$HomePhone’, CellPhone = ‘$CellPhone’, Email = ‘$Email’, College1 = ‘$College1’, College2 = ‘$College2′, College3 =’$College3’,Birth_Day = ‘$Birth_Day’, Birth_Month = ‘$Birth_Month’, Mem_Type = ‘$Mem_Type’, Honorary = ‘$Honorary’, Joined_Local = ‘$Joined_Local’, Joined_Natl = ‘$Joined_Natl’, Mailings = ‘$Mailings’, Positions_Held = ‘$Positions_Held’, Notes = ‘Notes’,Referred = ‘$Referred’, Retired = ‘$Retired’, Employer = ‘$Employer’,Occupation = ‘$Occupation’, Positions = ‘$Positions’, OtherWriteIn = ‘$OtherWriteIn’
    WHERE ID = ‘$ID’ “;`

    Thread Starter hsysgrp

    (@hsysgrp)

    $sql = “UPDATE AAUW_Members SET ID = ‘$ID’, Title = ‘$Title’, FirstName = ‘$FirstName’, LastName = ‘$LastName’, Address1 = ‘$Address1’, City = ‘$City’, State = ‘$State’, Zip = ‘$Zip’, HomePhone = ‘$HomePhone’, CellPhone = ‘$CellPhone’, Email = ‘$Email’, College1 = ‘$College1’, College2 = ‘$College2′, College3 =’$College3’,Birth_Day = ‘$Birth_Day’, Birth_Month = ‘$Birth_Month’, Mem_Type = ‘$Mem_Type’, Honorary = ‘$Honorary’, Joined_Local = ‘$Joined_Local’, Joined_Natl = ‘$Joined_Natl’, Mailings = ‘$Mailings’, Positions_Held = ‘$Positions_Held’, Notes = ‘Notes’,Referred = ‘$Referred’, Retired = ‘$Retired’, Employer = ‘$Employer’,Occupation = ‘$Occupation’, Positions = ‘$Positions’, OtherWriteIn = ‘$OtherWriteIn’
    WHERE ID = ‘$ID’ “;
    Dion

    (@diondesigns)

    I suggest that you take a look at the $wpdb->update() documentation:

    https://developer.www.ads-software.com/reference/classes/wpdb/update/

    You are missing the $where array, which is why the function converted your array of formats to a massive WHERE clause.

    Thread Starter hsysgrp

    (@hsysgrp)

    Exactly right, thank you.
    Now I have:
    $result_check = $wpdb->update(‘AAUW_Members’,
    array(
    ‘ID’ => $ID,
    ‘Title’ => $Title,
    ‘FirstName’ => $FirstName,

    ),
    array(
    ‘ID’ => $ID
    )
    );

    This worked after I removed the 29 types %d%, %s%, array. It is not critical here as the ID is an integer, but not calculated with. However, where do I insert the type array in this syntax if it is needed?

    Dion

    (@diondesigns)

    According to the documentation, the $format array should be immediately after the $where array. I can’t be of much more help here because I don’t use $wpdb unless it’s absolutely necessary (and it almost never is).

    Thread Starter hsysgrp

    (@hsysgrp)

    OK, will try that. thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unknown Column ‘0’ in where clause’ is closed to new replies.