dsozqcx9668 2014-08-20 12:13
浏览 35
已采纳

mysqli_real_escape_string无效[关闭]

I have looked all over the web, checked the php syntax but I can't understand why this code is not working.

  // Create connection
  $con=mysqli_connect("localhost","task_user","task","tasks");

  // Check connection
  if (mysqli_connect_errno()) {
    echo "No se puede conectar a la base de datos: " . mysqli_connect_error();
  }
  else{
    //Verificación de la información de logeo
    $username = $_POST["user"];
    $username = stripslashes($username);
    $password = $_POST["passwd"];    
    $username = $mysqli_real_escape_string($con,$username);
    //$password = $mysqli_real_escape_string($password);
    //$sqlquery = "SELECT username,password FROM users WHERE username ='$username' AND password='$password'";
  }


  echo '<script type = "text/javascript"> restoreValues("' . $_POST["user"] . '","' .  $_POST["passwd"] . '"); </script>';
  echo "ALL OK";

If I comment the mysqli_real_escape_string then it works (ALL OK is printed), if I don't it doesn't work. What am I doing wrong??

  • 写回答

2条回答 默认 最新

  • dongsou3041 2014-08-20 12:15
    关注

    you are using $ sign before function mysqli_real_escape_string

    make it

    $username = mysqli_real_escape_string($con,$username);
    

    instead of

    $username = $mysqli_real_escape_string($con,$username);
                ^ remove this  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?