FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Variables in Queries URGENT help needed!





polly-gone
Is it possible to put a variable into a query? This won't work:

Code:

$sql = "SELECT * FROM marketplace_users WHERE user_name = \'$username\'";
$result = mysql_query($sql) or die("Error in query...1");


I keep getting "Error in query... 1"

-Nick Smile Smile Smile
LukeakaDanish
Use:

Code:

$sql = "SELECT * FROM marketplace_users WHERE user_name = '$username'";


OR if you need more advanced variables (objects, arrays etc.) use:

Code:

$sql = "SELECT * FROM marketplace_users WHERE user_name = '{$array[3]}'";
AftershockVibe
The reason why your original version didn't work is because you escaped your single-quote marks using "\". So the database was literally looking for the string "$username".
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.