I have an sqlite database of mtcars data:
> mtcars
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
...
I have following html file which produces a form all right:
<html>
<form action="mtcars_action.php" method="post">
<p>Enter cyl (4,6,8): <input type="number" name="cyl" /></p>
<p>Enter gear (3,4,5): <input type="number" name="gear" /></p>
<p>Enter carb (1,2,3,4,6,8): <input type="number" name="carb" /></p>
<p><input type="submit"/></p>
</form>
</html>
I am trying to read mtcars.sqlite database and return output with following php code file (mtcars_action.php):
<?php
echo "<p>starting</p>" or die ("error 0");
$db = new SQLite3('/var/databases/mtcars.sqlite') or die("error 1") ;
$results = $db->query("select * from main where cyl=$_POST['cyl'] & gear=$_POST['gear'] & carb=$_POST['carb'] ;") or die("error 2");
while ($row = $results->fetchArray()) {
echo "model: $row[model]; ";
}
?>
This is not working. No output comes. Even 'starting' (from first print statement) does not come.
Keeping only one statement in the file works:
print($_POST['cyl'])
or 'gear' or 'carb' works all right, indicating that the numbers are being received all right.
Adding "$results = $db->query...." statement stops all output and I suspect the error is in this line. Removing "" does not help.
Where is the error and how can this be solved? I am using httpd (Apache) web server on Slackware Linux and testing it on localhost.
EDIT: I turned display_errors = on in php.ini file and I get this message:
Parse error: syntax error, unexpected 'main' (T_STRING) in /var/www/htdocs/mtcars_action.php on line 7 .
But 'main' is the name of a table in this database. The command 'select * from main;' works perfectly in sqlite3. The problem persists even after changing the name of the table from "main" to "mtcars".