Page 1 of 1

strange error help

Posted: Mon Jul 11, 2005 5:16 pm
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?

Posted: Mon Jul 11, 2005 5:32 pm
by pickle
Echo your query before you execute it and see what it looks like.

Posted: Mon Jul 11, 2005 5:39 pm
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">

Posted: Mon Jul 11, 2005 5:44 pm
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.

Posted: Mon Jul 11, 2005 5:54 pm
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'];?>"/>

Posted: Mon Jul 11, 2005 6:09 pm
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.