Page 1 of 1

sqlite query with "@" throwing errors

Posted: Fri Feb 02, 2007 6:25 am
by pedrotuga
I am migrating my forums to another forum script and also from mysql to sqlite....

this code returns errors on the sqlite query line

Code: Select all

$sql_get_users ="SELECT user_id,username,`password`,email,posts,date_added FROM	phorum_users WHERE active=1 AND user_id > 2";
					

$result_users = mysql_query($sql_get_users);

$sql_insert_users = array();

while ($row = mysql_fetch_assoc($result_users)){
	$sql_insert_users[]="INSERT INTO users (id,username,password, email,num_posts,registered) VALUES
		 (".$row["user_id"].",".$row["username"].",".$row["password"].",".$row["email"].",".$row["posts"].",".$row["date_added"].")";
}


foreach ($sql_insert_users as $iterador){
	$iterador = sqlite_escape_string($iterador);
	echo $iterador."<br />";
	sqlite_query ( $db, $iterador );
}

Warning: sqlite_query() [function.sqlite-query]: unrecognized token: "@" in ...


what am i missing here?

Posted: Fri Feb 02, 2007 6:33 am
by superdezign
Well unless it's earlier on in your code, the @ is from "email".... I've never used sqlite before,so maybe you should check how it handles @ signs.

Posted: Fri Feb 02, 2007 6:40 am
by xinnex
Try adding some apostrophes around those string-values in your insert-statement..

eg:

Code: Select all

,'".$row["username"]."','".$row["password"]."','".$row["email"]."', //etc..

Posted: Fri Feb 02, 2007 6:41 am
by superdezign
.... That would be the reason sqlite was looking at the literal value as a part of the query. Good eye.

Posted: Fri Feb 02, 2007 6:55 am
by pedrotuga
xinnex wrote:Try adding some apostrophes around those string-values in your insert-statement..

eg:

Code: Select all

,'".$row["username"]."','".$row["password"]."','".$row["email"]."', //etc..
it doesnt work :(

it keeps trowing the exact same error...

here is my new code:

Code: Select all

while ($row = mysql_fetch_assoc($result_users)){
	$sql_insert_users[]="INSERT INTO users
						(id,username,password, email,num_posts,registered)
						VALUES
						(".$row["user_id"].",'".$row["username"]."','".$row["password"]."','".$row["email"]."',".$row["posts"].",".$row["date_added"].")";
}

Posted: Fri Feb 02, 2007 7:30 am
by mikeq
Why dont you output the query string to your screen so you can see what it looks like before passing it to the function that tries to execute it as a query.

Posted: Fri Feb 02, 2007 12:18 pm
by pedrotuga
mikeq wrote:Why dont you output the query string to your screen so you can see what it looks like before passing it to the function that tries to execute it as a query.
if you check on my code i did just that. It looked ok, but then... double quotes cannot replace single ones when it comes to sql. The dummy error is that i am escaping the whole query, which doesnt make sense. I fixed it already, i should escape only the strings i will insert in the query rather then the query itself.

Thank you all for the quick help.