Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
nexus6
Forum Newbie
Posts: 20 Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark
Post
by nexus6 » Mon Jul 11, 2005 5:16 pm
insertError: [2 at line 46] sqlite_query() [function.sqlite-query]: unrecognized token: ":"
Error in query SQL logic error or missing database
this is my insert.php
Code: Select all
<?php
function errHandler($errno, $errstr, $errfile, $errline) {
echo "Error: <b>[$errno at line $errline] $errstr</b><br />\n";
}
set_error_handler("errHandler");
$db = "c:/server/sqlite/selection.db";
$handle = sqlite_open($db) or die("Could not open database");
$query = "";
if (isset($_POST['tableName'])){
$table = sqlite_escape_string($_POST['tableName']);
echo "insert";
if (!empty($_POST['title'])
&& !empty($_POST['info_dk'])
&& !empty($_POST['info_uk'])
&& !empty($_POST['land'])
&& !empty($_POST['vol'])
&& !empty($_POST['size'])
&& !empty($_POST['price'])) {
$id = md5(mktime());
$title = sqlite_escape_string($_POST['title']);
$info_dk = sqlite_escape_string($_POST['info_dk']);
$info_uk = sqlite_escape_string($_POST['info_uk']);
$land = sqlite_escape_string($_POST['land']);
$vol = sqlite_escape_string($_POST['vol']);
$size = sqlite_escape_string($_POST['size']);
$price = sqlite_escape_string($_POST['price']);
$query = "insert into $table (item_id, title, info_dk, info_uk, land, vol, size,price) values (
'$id',
'$title',
'$info_dk',
'$info_uk',
'$land',
'$vol',
'$size',
'$price')";
line 46 $result=sqlite_query($handle, $query) or die("Error in query ".sqlite_error_string(sqlite_last_error($handle)));
}
echo "Record added.";
}
echo "Returning to main.";
header ("Location: ../index2.php");
exit;
?>
i can't find the ":" in line 46 - how can i solve this?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Mon Jul 11, 2005 5:32 pm
Echo your query before you execute it and see what it looks like.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nexus6
Forum Newbie
Posts: 20 Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark
Post
by nexus6 » Mon Jul 11, 2005 5:39 pm
this is my info from the echo query:
Error: [8 at line 10] Undefined variable: query
insertError: [2 at line 48] sqlite_query() [function.sqlite-query]: unrecognized token: ":"
Error in query SQL logic error or missing database
i have tried to add this to my add.php, so the item is send to insert.php
<FORM method="POST" action="actions/insert2.php">
<input type="hidden" name="tableName" value="<?=$_GET['tableName'];?>"/>
<TABLE cellpadding="0" cellspacing="0">
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Mon Jul 11, 2005 5:44 pm
No, that's the error string generated by SQLite. It's usually hard to tell what part of the query is wrong, without knowing exactly what the query was that generated the problem. Right before line 46, call:
Code: Select all
echo "e;<pre>$query</pre>"e;;
and look at that syntax.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nexus6
Forum Newbie
Posts: 20 Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark
Post
by nexus6 » Mon Jul 11, 2005 5:54 pm
this is what i got:
insert into
Notice: Undefined index: tableName in C:\Server\Apache Group\Apache2\htdocs\admin\add.php on line 24
(item_id, title, info_dk, info_uk, land, vol, size,price) values (
'60fba4de76db9e2684fcb3b626b8c1b2',
'x',
'x',
'x',
'x',
'x',
'x',
'x')
Error: [2 at line 47] sqlite_query() [function.sqlite-query]: unrecognized token: ":"
Error in query SQL logic error or missing database
my line 24 from add.php is:
<input type="hidden" name="tableName" value="<?=$_GET['tableName'];?>"/>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Mon Jul 11, 2005 6:09 pm
Then it looks like $table is being assigned a value of an error statement. I can't see where exactly - output $table by itself to make sure.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.