building a sql query string with php parameters


I'm trying to do this, but it returns null?


and then

getType = mysql_query("SELECT * FROM wines WHERE $query_1") or die(mysql_error());

while if i do like this:

 $getType = mysql_query("SELECT * FROM wines WHERE $field_name[0]='{$field_value[0]}'") or die(mysql_error());

it works fine.

is this even possible, or am I missing something too obvious? thank you in advance!




You are building it the wrong way. You should never use curly brackets (or any other string) in a SQL query. Concatenate your query instead.

Like this:


and oh, you missed a $ before your query, thats why its null.




This works for me:

$field_name[0] = "test";
$field_value[0] = "someting";
echo ("SELECT * FROM wines WHERE $query_1") or die(mysql_error());

Hope it helps

People are also looking for solutions to the problem: Building custom PHP extension (.so)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.