<?php
require "connect.php";
$file = "./myFile2.txt";
$document = file_get_contents($file);
$lines = explode("\n",$document);
foreach($lines as $newline) {
$arr = explode(': ', $lines[0]);
$order = $arr[1];
/* echo $order.'<br>'; */
}
foreach($lines as $newline){
$art = explode(': ', $newline);
$total = $art[1];
echo $total.'<br>';
$sql = "USE receipts INSERT INTO receipt_content (total_price) VALUES ($total)";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
When attempting to add the echoed information into my database (phpmyadmin) [MariaDB server], I get the following error:
12364
Error: USE receipts INSERT INTO receipt_content (total_price) VALUES (12364 ) 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 'INSERT INTO receipt_content (total_price) VALUES (12364 )' at line 1
600$
Error: USE receipts INSERT INTO receipt_content (total_price) VALUES (600$) 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 'INSERT INTO receipt_content (total_price) VALUES (600$)' at line 1
I have a database called 'receipts' with table 'receipt_content', containing column 'total_price' and 'order_number'.
How can i fix the error to properly insert the parsed data ('12364' and '600$') into the columns of the tables of my database.