strange error help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
nexus6
Forum Newbie
Posts: 20
Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark

strange error help

Post by nexus6 »

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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

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.
User avatar
nexus6
Forum Newbie
Posts: 20
Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark

Post by nexus6 »

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">
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

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 &quote;<pre>$query</pre>&quote;;
and look at that syntax.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
nexus6
Forum Newbie
Posts: 20
Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark

Post by nexus6 »

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'];?>"/>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

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.
Post Reply