简体   繁体   中英

PHP: Handle the ' and " in file handling and SQL

I have a file that contains both single quote(') and double quote("). There is a field in database where i am saving the content of the file.

Now, the problem arises in the SQL query as ' and " conflicts with each other. There is ' quote in SQL query and file content has their own. So, they are conflicting. How can i handle this?

Here is the code which i am trying to do:

$filename = "folder/file.txt";
$file_content = file_get_contents($filename);
$sql = 'INSERT INTO table (content)
        VALUES ('.$file_content.')';
if ($conn->query($sql) === TRUE) {
    echo "value submitted";
}else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

Please help.

在使用mysql_real_escape_string方法进行插入之前,请转义该字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM