当我试图在texta中插入一些带有撇号的文本到mysql数据库时,它只是不会插入任何东西,任何人都知道这是为什么? 我希望有人可以帮助我。
一些代码
PHP
foreach ($_POST['episode'] as $episode => $value ) {
$episode_title = $value['episode_title'];
$episode_filename = $value['episode_filename'];
$episode_image = $value['episode_image'];
$episode_description = $value['episode_description'];
$subtitle_language = $value['subtitle_language'];
$subtitle_filename = $value['subtitle_filename'];
$image_extension = $value['image_extension'];
$sql_episode = "INSERT INTO episodes VALUES ('', '$episode_title', '$episode_filename', '$episode_image', '$episode_description', '$subtitle_language', '$subtitle_filename', '$image_extension', '$inserted_child_id', '$inserted_cover_id')";
if ($db->query($sql_episode) === TRUE) {
$inserted_episode_id = $db->insert_id;
}
}
HTML
<textarea name="episode[0][episode_description]" placeholder="Episode Description..."></textarea>
答案 0 :(得分:1)
你需要逃避&#39;你的字符串,所以引号不会破坏代码结构。将您发布的变量传递给以下一个或多个:
mysqli_real_escape_string($db,$string);
addslashes($string);
或其他类似的功能,转换或逃避&#39;引号。
例如:
$episode_description = mysqli_real_escape_string($db,$value['episode_description']);