php - There was an error running the query [Unknown column 'test' in 'where clause'] -


this question has answer here:

i have database row called "username". need show value of other row depending on username logged in. so, have following script:

$db = new mysqli('', '', '', '');  if($db->connect_errno > 0){     die('unable connect database [' . $db->connect_error . ']'); }  $sql = <<<sql     select * `users` username = $username    sql;  if(!$result = $db->query($sql)){     die('there error running query [' . $db->error . ']'); }  while($row = $result->fetch_assoc()){   $text_cli = $row['text_cli'];   $text_trad = $row['text_trad']; } 

and value of $username stored previously.

and finally:

<div id="text_cli"><?php echo $text_trad ?></div> <div id="text_cli"><?php echo $text_cli ?></div> 

but error: there error running query [unknown column 'test' in 'where clause'].

"test" fake username created test code.

thank help.

just put username variable inside quotes in sql this: '$username'

select * `users` username ='$username' 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -