Yosra MH
Yosra MH

Reputation: 159

$wpdb :SELECT... WHERE

When I use this, it works well and I have no problem:

$user = $_POST['uusername'];
$result=$wpdb->get_results("SELECT * FROM Materials");
foreach($result as $print)
{ echo '<pre>',print_r($print->id_customer,1),'</pre>'; }
$wpdb->print_error();

But when I try to fetch a user, it doesn't work and the worst is that I don't even get an error message:

$user = $_POST['uusername'];
$result=$wpdb->get_results("SELECT * FROM Materials WHERE mtrname=$user");

Is there any error whith this SELECT?

Upvotes: 1

Views: 337

Answers (1)

Bhumi Shah
Bhumi Shah

Reputation: 9476

If you post value is string pass single quote:

$result=$wpdb->get_results("SELECT * FROM Materials WHERE mtrname='$user' ");

Upvotes: 1

Related Questions