doukucai0099 2019-03-15 19:27
浏览 57
已采纳

如何使用PHP从中获取带有撇号的MySQL中的所有数据

I am trying to pull data from MySQL record that has an apostrophy. It comes back with a backslash and rest of string missing. Trust me, I have scoured the internet and nothing so far is working. I must be too tired out on it and it is right in front of me. See code below ...

$sql = "SELECT * FROM ".$tbl."  WHERE FIELD_NO = ".$order_no." ORDER BY LINE_NO ASC";
    $rs_result = $conn->query($sql); 

while($row = $rs_result->fetch_assoc()) {

$addl_info = mysqli_real_escape_string($conn, $row['ADDL_INFO']); //tried this

echo "<td class='col32'><input name='addl_info[]' class='addl_info' type='text' value='".$addl_info."'></td>";

The mysql stored data is "Band of 20's" and it outputs as "Band of 20\" with the 's' missing. I tried everything I can imagine and still I cannot get my full data string returned using PHP. I used mysqli_real_escape_string() to get the data in with the apostrophe but now I cannot get the data back out with the apostrophe and the text that follows it.

I plan to use this particular project to move over to PDO, but I need a fix for now until I can do that. It will take me some time to learn and accomplish PDO.

  • 写回答

3条回答 默认 最新

  • dtbam62840 2019-03-15 19:35
    关注

    You're enclosing your value in single quotes, this won't work:

    value='Band of 20's'
    

    See the problem? How would the browser know which is a starting quote and which is an ending one?

    You need to convert the quote into it's HTML entity &#039;:

    echo "stuff value='".htmlentities($row['ADDL_INFO'], ENT_QUOTES)."' stuff";
    

    Or use double quotes (however you should still convert HTML entities):

    echo "stuff value=\"{$row['ADDL_INFO']}\" stuff";
    //or
    echo 'stuff value="'.$row['ADDL_INFO'].'" stuff';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序