I'm missing something here.
I simply want to get data from my database.
So I tried this but keeps giving me an error.
global $wpdb;
$sql = "SELECT * FROM $wpdb->postmeta WHERE group='$group'";
$results = $wpdb->get_results($sql) or die(mysql_error());
foreach( $results as $result ) {
echo $result->company_name;
}
$group
is a parameter passed in the url the variable is $group = $_GET['group'];
This is the error:
WordPress database 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 'group='bicyclegroup'' at line 1] SELECT * FROM xx_postmeta WHERE group='thegroup' 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 'group='thegroup'' at line 1
Can somebody please help me fix this once and for all so I can save it locally and use it for further projects :-)
or die( mysql_error() );
is bad, in newer versions of WordPress and PHP the mysql extension isn't even used ( the mysql extension and all themysql_
functions are deprecated in favour ofmysqli
, you should avoid them ). Instead check the value of$results
and check for an error value