I'm trying to use the following script in PHP to get a name into a variable:
$fileop = fgetcsv($handle,1000,";")
$prod_no = " SELECT no FROM e_produit WHERE nom LIKE ".$fileop[0]." ";
$stmt = $pdo->query($prod_no);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row;
But all I get in the page is the following error:
ERROR PDO Statement => errorCode=' SELECT no FROM e_produit WHERE nom LIKE NAVIGATOR 80G ' | error info =array ( 0 => '42000', 1 => 1064, 2 => '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 \'80G\' at line 1', ) in C:\wamp\www\ma-fourniture\liens\pdo2.php on line 64"
You need to make a DB connection and execute your query, like
$db = new PDO('mysql:host=YOUR_HOSTNAME;dbname=YOUR_DBNAME;charset=utf8', 'YOUR_DB_USERNAME', 'YOUR_DB_PASSWORD');
$prod_no = " SELECT no FROM e_produit WHERE ".$fileop[0]." LIKE nom ";
$stmt = $db->query($prod_no);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
look at php PDO
You are not doing any sort of query at all. You are only assigning the query string to a variable. This is what you need:
list($prod_no) = mysql_fetch_array(mysql_query(" SELECT no FROM e_produit WHERE ".$fileop[0]." LIKE nom "));
However, this is using just MySQL, assuming that is what you are using. If you do not know how to use MySQL with PHP, you need to do tutorials.