0

I'm saving queries in my DB as strings
here's my code:

$SQLcode="SELECT *	
FROM ...
WHERE field="blah blah"
HAVING field2<$x";


$query = "INSERT INTO tblQ (qId, qName, description, SQLcode) VALUES (NULL, '$qName', '$description', '$SQLcode');";

the problem is inserting a string into the $SQLcode, if I do it this way:
$SQLcode= " SELECT * FROM ...WHERE field=' blah blah ' HAVING field2<$x ";
it makes problem with the $query cuz there are ' around the $SQLcode:
$query = "INSERT INTO tblQ (qId, qName, description, SQLcode) VALUES (NULL, '$qName', '$description', '$SQLcode');";

if I do it like this:
$SQLcode='SELECT * FROM ...WHERE field="blah blah" HAVING field2<$x';
then the $x is saved as "$x" and not as the value in it..

is there a way around this craziness? gotta be..!

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by cereal
1

You need double quotes, otherwise $x won't be processed. An alternative is this:

'SELECT * FROM ...WHERE field="blah blah" HAVING field2<'.$x

Edited by cereal: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.