gpt4 book ai didi

php - 从 MySQL 检索 mysqli_real_escape_string

转载 作者:行者123 更新时间:2023-11-29 08:33:04 25 4
gpt4 key购买 nike

// inserting into DB from form

if (!empty($_POST['Title'])) {
$t = mysqli_real_escape_string($dbc, ($_POST['Title']));
} else {
$errors[] = 'Please enter a Headline title';
}

// Add the news to the database:

$q = 'INSERT INTO news ( Title, Content) VALUES (?, ?)';
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt, 'ss', $t, $c);
mysqli_stmt_execute($stmt);

如果 $t 包含撇号,例如

We're awesome

它将把它添加到数据库中

"we\'re awesome"

稍后:

然后如何运行一个查询,其中 title = $t

$q = "SELECT * FROM news WHERE title= '$t'";

查询失败,因为撇号有效地切断了 SQL

SELECT * FROM news WHERE title = ' we're awesome

最佳答案

您可以转义或使用准备好的语句,但不能同时使用!

关于php - 从 MySQL 检索 mysqli_real_escape_string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16020480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com