PHP creates query that has to be edited before it will run in MySql
My PHP program generates a query as follows:
MY code:
$strA="`IDno`,`VendorId`,`AccountNo`,";
$strB.="`Category`,`Internet`,`Internet2`,";
$strB= "`Company`, `Email`,`Email2`,`Phone`, ";
$strB.="des_decrypt(`internetid`, '".$key."') AS 'internetid', ";
$strB.="des_decrypt(`PW`, '".$key."') AS 'PW', ";
$strB.="des_decrypt(`licensekeypin`, '".$key."') AS 'license', ";
$strB.="`EmailOfRecord`,`Hints`";
$str=$strA.$strB;
$query = "SELECT ".$str." FROM `account` WHERE `IDno`= '".$recId."';";
MySql query produced:
SELECT `recId`,`key`,`IDno`,`VendorId`,`AccountNo`, `Category`,`Internet`,`Internet2`, `Company
`, `Email`,`Email2`,`Phone`, des_decrypt(`internetid`, 'alibaba511')AS 'internetid',des_decrypt(`PW`, 'alibaba511') AS 'PW', des_decrypt(`licensekeypin`, 'alibaba511') AS 'license', `EmailOfRecord`, `Hints` FROM `account` WHERE `Company`= 'Fay School';
Notice how the line splits:
.... `Company
`, `Email`, ...... where the closing ` in `Company` falls on another line.
the query then won't work. It must be edited to work.
In the code above the $strA, $strB is just an attempt to get $query to produce a MySql query that will work. How can I code this so this doesn't happen?
Thanks,
R