mysqli_real_escape_string not working properly

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I've searched and yet nothing I find seems to work.

My problem is that when using special characters as ' the input query breaks. Now, I tried using the mysqli_real_escape_string on my string, but this returns a blank value. I read that the mysqli_real_escape_string should be placed AFTER the database connection, and as far as I know, that is what I have done, yet it returns blank values.

Here's the code:

<?php  session_start();   if (isset($_POST['submit'])) {     require_once 'connect.php';      $title = mysqli_real_escape_string($_POST['title']);     $article = mysqli_real_escape_string($_POST['article']);      $query = "INSERT INTO Articles                 (Title, content)                 VALUES                  ('$title', '$article')";      $result = mysqli_query($connect, $query) or die('could not query database');      $_SESSION['artcle'] = 1;     $_SESSION['artcle'] = $title;       mysqli_close($connect);     header('Location: CENSORED'); } ?> 

回答1:

You forgot your resource parameter:

$title = mysqli_real_escape_string($connect, $_POST['title']); 

PHP Manual



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!