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条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站