我有這個腳本。mysqli_real_escape_string使空字符串
<?php
session_start();
if (!isset($_POST['text']) || $_POST['text'] == "" || strlen($_POST['text']) < 5) {
echo "error";
echo '<meta http-equiv="refresh" content="2;url=../prispevky/add.php">';
return 0;}
else $text = $_POST['text'];
if (!isset ($_SESSION['nick'])) {
echo "error";
echo '<meta http-equiv="refresh" content="2;url=../error.php">';
return 0;}
else $nick = $_SESSION['nick'];
$time = time();
$farby = array("red","blue","green", "brown", "orange", "purple", "grey", "lime", "yellow", "pink");
include_once "../inkludy/conect.php";
$new = $_POST['text'];
echo $new;
$new = mysqli_real_escape_string($_POST['text']);
echo $new;
$new = str_replace(array("\\r\\n", "\n"), "</br>", $new);
for ($i=0;$i<10;$i++){
if (preg_match ('/< .{1,10} >/', $new, $meno)){
$nove_meno = preg_replace('/(<)|(>)/', '', $meno[0]);
$new = preg_replace('/' . $meno[0] . '/', '<b style="color:' . $farby[$i] . '">>' . $nove_meno . '<</b>', $new);
}
}
try {
$query = "INSERT INTO hlasky (autor,text,onoff,time) VALUES (:nick,:new,:onoff,:time)";
$stmt = $conn->prepare($query);
$stmt->bindValue(':nick', $nick, PDO::PARAM_STR);
$stmt->bindValue(':new', $new, PDO::PARAM_STR);
$stmt->bindValue(':onoff', '1', PDO::PARAM_INT);
$stmt->bindValue(':time', $time, PDO::PARAM_INT);
$stmt->execute();}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();}
?>
<meta http-equiv="refresh" content="10;url=../hmenu/najn.php">
$ _ POST = 「asdasd」 和
$new = $_POST['text'];
echo $new;
作品的權利,但和回聲asdasd但
$new = mysqli_real_escape_string($_POST['text']);
echo $new;
使得$新的空白。人人都認爲我沒有MySQL連接,但我和
INSERT INTO hlasky (autor,text,onoff,time) VALUES (:nick,:new,:onoff,:time)
工作太多,但新空 你能幫助我如何不失去$新的字符串?
這是我包含的連接腳本include_once「../inkludy/conect.php」;
<?php
$server = "localhost";
$username = "";
$password = "";
$databaza_meno = "iz";
$dsn = "mysql:unix_socket=/tmp/mysql50.sock;dbname=$databaza_meno";
$conn = new PDO($dsn, $username, $password);
$db_spojenie = mysql_connect($server, $username, $password);
$db = mysql_select_db($databaza_meno, $db_spojenie);
mysql_query("SET NAMES utf-8");
?>
你不應該在PDO中使用* real_escape_string。哦你的混合mysql和mysqli和pdo所有togeather – 2014-03-02 02:17:20
你爲什麼混合'mysql_ *'和PDO? –
所以我應該只使用PDO或real_escape_string? – OdkoPP