This question already has answers here:
How can I prevent SQL injection in PHP?
                                
                                    (28个答案)
                                
                        
                                4年前关闭。
            
                    
早上好,

我对php的SQL插入命令有疑问。我正在尝试以下代码:

$TeamMatchTable = "INSERT INTO Team Match Table
                  (LineupForward) VALUES ('$HomeLineupForward')";`


但是,$HomeLineupForward变量的内容为:Alexandre D'Acol;

由于',这将导致错误。

我该怎么做才能解决这个问题?

最佳答案

你可以试试看

$HomeLineupForward= mysql_real_escape_string($HomeLineupForward);

$TeamMatchTable = "INSERT INTO Team Match Table ('LineupForward') VALUES ('$HomeLineupForward')";

10-04 14:39