使用php(撇号)在mysql数据库中保存Textarea中的文本

时间:2013-02-18 15:52:02

标签: php mysql

HTML

<form id = "recall_TextArea2" method="post" action="SaveRecall2.php">
    <center><textarea name="recall_Info" cols="60" rows="30em"></textarea></center>
</form> 

PHP

if (isset($_POST['recall_Info'])) {
    $recall_Info = $_POST['recall_Info'];
}
else {
    echo "nothing was recalled.";
}

$recall_Info = stripslashes($recall_Info);
$recall_Info = mysqli_real_escape_string($recall_Info);
$update_sql = "UPDATE  `participants` SET  `recall_1` =  '$recall_Info' WHERE  `school_id` =825776 LIMIT 1 ;";

我希望能够在包含撇号的文本区域中键入文本,但每次尝试时都不起作用。

当我取出

时,它会保存正常文本(无撇号)
$recall_Info = stripslashes($recall_Info);
$recall_Info = mysqli_real_escape_string($recall_Info);

1 个答案:

答案 0 :(得分:1)

我会说看看您是否正确访问了表单/发布数据。也许在sql之前回显你的表单数据,看看发生了什么。

这对我有用,我没有改变你的SQL查询:

$username = "root";
$password = "root";
$host = "localhost";
$dbname = "test";

$mysqli = new mysqli($host, $username, $password, $dbname);

$recall_Info ="this is new recall info text";

$update_sql = "UPDATE  `participants` SET  `recall_1` =  '$recall_Info'  '' WHERE       `school_id` ='825776' LIMIT 1;";

$stmt = $mysqli->stmt_init();
$stmt->prepare($update_sql);
$stmt->execute();

if ($stmt->affected_rows > 0) {
$OK = true;
}
if ($OK) {
echo 'update successful';
}