My value has apostrophe like this example "Johnesia's book" and i want to insert it in the table but it interfere with sql query, And data is stored in the variable so i can't add backslash.
I've tried to add escapement on a single data and found to be perfect but data are from excel so i can't modify all data as they are so many here is my code `$msg = ''; if(isset($_POST['import'])){ $filename = $_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($col = fgetcsv($file, 10000, ",")) !== FALSE)
{
$insert = "INSERT INTO products (product_name,qty,price,s_price,profit)values('".$col[0]."','".$col[1]."','".$col[2]."','".$col[3]."','".$col[4]."')";
mysqli_query($con,$insert);
}
$msg = '<p style="color: green;"> CSV Data inserted successfully</p>';
}
}`
Sample data is for item name is Neocast Plaster of Paris 10cm x 2.7m (1's)
this is the error message Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's)','5','780','1500','720')' at line 1 in C:\xampp\htdocs\import-excel-to-mysql\index.php:24 Stack trace: #0 C:\xampp\htdocs\import-excel-to-mysql\index.php(24): mysqli_query(Object(mysqli), 'INSERT INTO pro...') #1 {main} thrown in C:\xampp\htdocs\import-excel-to-mysql\index.php on line 24