how do I use mysql real escape string?

前端 未结 3 1978
故里飘歌
故里飘歌 2021-01-20 00:42

The code here is still incomplete because I\'m still going to ask you guys on what the proper format/syntax of using mysql escape string. Im still a beginner in php and I wa

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-20 01:04

    You'll need to escape the values before you put them into the query:

    $hnum = mysql_real_escape_string($_POST['hnum']);
    $query = "INSERT ... VALUES('$hnum')";
    

    If you have a lot of values, you can loop over them:

    $values = $_POST;
    
    foreach ($values as &$value) {
        $value = mysql_real_escape_string($value);
    }
    
    $query = "INSERT ... VALUES('$values[hnum]')";
    

提交回复
热议问题