Kelvin Halim Kelvin Halim - 6 months ago 8
SQL Question

Error in SQL syntax Check Manual Correspond to MySQL server

I'm getting this error:


Error Number: 1064

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 'from uhd_product where product_name and product_code like '%654321%'' at line 1


MySQL Query look like:

SELECT from uhd_product where product_name and product_code like '%654321%'


PHP Function:

function search($cari)
{
$cari=$this->db->query("SELECT from uhd_product where product_name and product_code like '%$cari%' ");
return $cari->result();;
}


Can anyone help me to solve this? I am doing a search with 2 record value in my database.

Answer

Try this Query:

SELECT * FROM uhd_product 
      where product_name like '%$cari%' 
      OR product_code LIKE '%$cari%'