dtxpz8785 2011-02-26 21:44
浏览 43
已采纳

如何使用PHP将文件路径插入MySQL表?

I'm trying to insert a file path into an empty MySQL table with PHP 5 but slashes and other characters are removed so I can not use to the string when calling it from the table. What function do I use to preserve the file path without losing characters?

$rawpath    = "F:\Business\test.htm";
$url        = "Business";

$query      = "INSERT IGNORE INTO `sites` (`url`,`base`)".
              "VALUES ('$rawpath','$url');";
echo $query;

Outputs: INSERT IGNORE INTO sites (url,base) VALUES ('F:\Business\test.htm','Business');

$query      = "SELECT * FROM `sites` WHERE `base`='Business';";
$row        = mysql_query($query);
$url        = mysql_result($row,0,"url");

echo $url;

Outputs: F:Businesstest.htm

  • 写回答

3条回答 默认 最新

  • douyin8623 2011-02-26 21:51
    关注

    Your problem is with backslashes \, which are used often to escape certain characters. You need to escape this backslashes (with another backslash), to make them appear. So, if you use double quotes, write \\ instead of just \, or use addslashes($url).

    I'm not quite sure that you need to escape them if you use just single quotes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)