-4

エラーが発生しています: SQL 構文にエラーがあります。near '){ concat(' Glucose Oxidase', '|', ' 4.2-6.4 mmol/l', '|', 'o'), } を使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。 else {' 4 行目

グルコースオキシダーゼ、4.2-6.4 mmol/l、o はフォームから取得されます。

 $sql="INSERT INTO adenclinicalchemistry (idclinicalchemistry, Glucose, totalcholesterol, triglyceride, highdensitylipoprotein, lowdensitylipoprotein, 
                bloodureanitrogen, creatinine, blooduricacid, sgot, sgpt, status, date, patientid, userid) 
                VALUES ('',
                if($exams[0] != ''){
                    concat('$_POST[glumet]', '|', '$_POST[glunor]', '|', '$_POST[glures]'),
                } else { 
                    concat('', '|', '', '|', ''),
                }
                if($exams[1] != ''){
                    concat('$_POST[cholmet]', '|', '$_POST[cholnor]', '|', '$_POST[cholres]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                if($exams[2] != ''){
                    concat('$_POST[trimet]', '|', '$_POST[trinor]', '|', '$_POST[trires]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                if($exams[3] != ''){
                    concat('$_POST[himet]', '|', '$_POST[hinor]', '|', '$_POST[hires]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                }if($exams[4] != ''){
                    concat('$_POST[lowmet]', '|', '$_POST[lownor]', '|', '$_POST[lowres]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                }if($exams[5] != ''){
                    concat('$_POST[ureamet]', '|', '$_POST[ureanor]', '|', '$_POST[ureares]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                }if($exams[6] != ''){
                    concat('$_POST[cremet]', '|', '$_POST[crenor]', '|', '$_POST[creres]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                }if($exams[7] != ''){
                    concat('$_POST[uricmet]', '|', '$_POST[uricnor]', '|', '$_POST[uricres]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                }if($exams[8] != ''){
                    concat('$_POST[astm]', '|', '$_POST[astm]', '|', '$_POST[astm]'),
                }else {
                    concat('$_POST[astmet]', '|', '$_POST[astnor]', '|', '$_POST[astres]'),
                }
                }if($exams[9] != ''){
                    concat('$_POST[altmet]', '|', '$_POST[altnor]', '|', '$_POST[altres]'),
                }else{
                    concat('', '|', '', '|', ''),
                }
                'confirm1', 
                '$date',
                '$_POST[patid]',
                '" .$_SESSION['user']. "')";
4

3 に答える 3

1

コードを文字列内に記述した場合、PHP はコードを解釈しません。

文字列の外に置き、SQL を適切に生成します。

于 2013-01-28T09:47:20.050 に答える
0

php で concat を実行し、変数を SQL クエリに渡します。

$str = '';
if($exams[0] != ''){
 $str .=$_POST['glumet'] . '|' . $_POST['glunor'] . '|' . $_POST['glures'];
} else { 
 $str .='| |';
}
..similar for others and user $str in your query
于 2013-01-28T09:47:29.890 に答える