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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog