任何人都可以幫忙。我試圖在傳遞給PHP的內部消息傳遞服務的值上使用mysql_real_escape_string來支持我的安全性,但是我必須在某處找到語法錯誤,因爲這些值沒有被插入到數據庫中。我四處尋找教程,幫助等,但努力做到了。用mysql_real_escape_string掙扎
我使用的代碼如下。尚未轉義的值($ email,$ from,$ time)正確輸入,但其他值僅輸入空白。
<?php
session_start();
$conn = mysqli_connect('localhost', 'username', 'password', 'dbname');
$email=$_SESSION['email'];
$to = $_POST ['touser'];
$toemail = $_POST['touseremail'];
$from = $_SESSION['name'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$time = time();
$query ="INSERT INTO messages
(to_user, to_email, subject, message, from_user, from_email, daterecord)
VALUES (
'" . mysql_real_escape_string($conn, $to) . "',
'" . mysql_real_escape_string($conn, $toemail) . "',
'" . mysql_real_escape_string($conn, $subject) . "',
'" . mysql_real_escape_string($conn, $message) . "',
'$from', '$email', '$time')";
$send = $conn -> query($query);
echo "Message sent!";
?>
支持安全=停止使用'mysql_real_escape_string'並使用[* prepared statements *](http://j.mp/T9hLWi)。 – Kermit 2013-03-27 15:38:16
此功能已棄用。不要使用它。 – meagar 2013-03-27 15:39:35
[MySQL](http://www.php.net/manual/en/book.mysql.php)≠[MySQLi](http://www.php.net/manual/en/book.mysqli.php) – Gumbo 2013-03-27 15:40:09