sqlite query with "@" throwing errors

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
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

sqlite query with "@" throwing errors

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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..
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

.... That would be the reason sqlite was looking at the literal value as a part of the query. Good eye.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post 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"].")";
}
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

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