doudouba4520 2016-10-19 21:29
浏览 109

使用mysqli_real_escape_string()将数据写入mysql但没有&

iam using this code below, but the character "&" will not be inserted into the db, also when i copy/paste some text from other pages and put it into the db the text ends for example in the middle of the text, dont know why, i tried also addslashes() and htmlspecialchars() or htmlentities().

i read mysqli_real_escape_string() is againt SQL injection attacks and htmlspecialchars() against XSS attachs, should i also combine them ?

$beschreibung = mysqli_real_escape_string($db, $_POST['beschreibung']);   
  • 写回答

2条回答 默认 最新

  • douhun7609 2016-10-19 21:44
    关注

    SQL Injection is merely just improperly formatted queries. What you're doing is not enough, stop now. Get into the practice of using prepared statements..

    $Connection = new mysqli("server","user","password","db");
    $Query = $Connection->prepare("SELECT Email FROM test_tbl WHERE username=?");
    $Query->bind_param('s',$_POST['ObjectContainingUsernameFromPost']);
    $Query->execute();
    $Query->bind_result($Email);
    $Query->fetch();
    $Query->close();
    

    Above is a very basic example of using prepared statements. It will quickly and easily format your query.

    My best guess to what is happening, I'm assuming you're just using the standard:

    $Query = mysqli_query("SELECT * FROM test_tbl WHERE Username=".$_POST['User']);
    

    As this query is not properly formatted you may have the quotes in your chunk of text which close the query string. PHP will then interpret everything as a command to send to the SQL server

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题