Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loosing / in sql

Guest
Mar 26, 2008 Mar 26, 2008
Im using cfdirectory to read a directory, and then adding the filename, size, directory into mysql 5 database.

Code:


<cfdirectory action="list" directory="D:\Backup\Cv'z" name="files" sort="Name desc" recurse='true' >
<cfset a = 1>
<cftable query="files" colheaders="yes" htmltable="no" border="yes" maxrows="10">
<cfcol text="#a#" >
<cfcol text="#type#">
<cfcol text="#size#">

<cfquery datasource="Intranet" name="addcv">
Select * from files
where File_Name = '#name#'
and File_Folder = '#directory#'
</cfquery>
<!--- Inserts file into DB ---->
<cfquery datasource="Intranet" name="insertCV">
Insert into files
(File_Name, File_Folder, File_Size)
values
('#name#', '#directory#', '#size#')
</cfquery>
<cfif addcv.recordcount gt 0>

<cfcol text="<font color=red>#name#</font>">
<cfelse>
<cfcol text="#name#">
</cfif>

<cfcol text="#directory#\#name#">
<cfset a = a + 1>

</cftable>




It inserts D:BackupCv'zSalesTyped Cvs

instead of d:\BackupCv's\Sales\Typed CVs

Why is it removing the \'s ?
TOPICS
Database access
360
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 26, 2008 Mar 26, 2008
I'm not familiar with MySql but in some languages you must escape slashes used in strings.

One or both of these:
1. Use cfqueryparam in your insert statement, it will properly escape single quotes so it may also handle the slashes for you.

2. Escape the slashes by doubling them "d:\BackupCv's\Sales\Typed CVs" becomes: d:\\BackupCv's\\Sales\\Typed CVs"
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2008 Mar 26, 2008
LATEST
yes, \ [backslash] in mysql is an 'escape character' - a special
character used to escape other special characters in strings and string
patterns. to use an actual \ character in a string you must also escape it.
<cfqueryparam> tag DOES properly escape this mysql escape character, so
use it.

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources