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..!

Recommended Answers

All 3 Replies

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

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

but OF COURSE!!! thank you!

You're welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.