이 스크립트가 있습니다.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");
?>
* real_escape_string을 PDO와 함께 사용해서는 안됩니다. 오, 당신은 mysql과 mysqli를 혼합하고 pdo는 모두 togeather입니다. –
왜 mysql_ *와 PDO를 혼합하고 있습니까? –
그래서 PDO 또는 real_escape_string 만 사용해야합니까? – OdkoPP