renno Posted September 13, 2006 Share Posted September 13, 2006 Hi,I've written a file path to a database but when I look at the records in the database it has erased the slashes indicating the change of folders... for example...C:\new\folder\filename.extbecomesc:newfolderfilenameDo I have to use addslashes() in some way? I have tried it but nothing seems to be changing.Also, when I use php to retrieve the database information instead of returning 'c:newfolderfilename' it displays 'Resource id #3'.Any help would be very much appriciated...Cheers Quote Link to comment https://forums.phpfreaks.com/topic/20634-writing-to-db-my-slashes-disappear/ Share on other sites More sharing options...
ober Posted September 13, 2006 Share Posted September 13, 2006 Can you post your code? Quote Link to comment https://forums.phpfreaks.com/topic/20634-writing-to-db-my-slashes-disappear/#findComment-91163 Share on other sites More sharing options...
renno Posted September 13, 2006 Author Share Posted September 13, 2006 [b]THE UPLOAD CODE:[/b][code]<?php$uploadDir = 'C:\Program Files\xampp\htdocs\Sites\Test\uploads\#';if(isset($_POST['upload'])){ $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } print "File uploaded to $filePath"; if ($dbc = mysql_connect ('localhost', 'us', 'pw)) { print '<p>Successfully connected to MySQL.</p>'; if (@mysql_select_db ('client_db')) { print '<p>The database has been selected.</p>'; } else { die ('<p>Could not select the database because: <b>' . mysql_error() .'</b></p>'); } if(!get_magic_quotes_gpc()) { //$fileName = addslashes($fileName); //$filePath = addslashes($filePath); } $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); mysql_close(); echo "<br>Files uploaded<br>"; }}?>[/code][b]view path/image code:[/b][code]<?php ini_set ('display_errors',1);error_reporting (E_ALL & ~E_NOTICE);//Connect and select---------------------------------------------------------- if ($dbc = mysql_connect ('localhost', 'tom', 'ickellious')) { if (!@mysql_select_db ('client_db')) { die ('<p>Could not select the database because: <b>'. mysql_error().'</b></p>'); } } else { die ('<p>Could not connect to MySQL because: <b>'. mysql_error().'</b></p>'); }//---------------------------------------------------------------------------- $query = "SELECT path FROM upload2"; $result = mysql_query ($query); print "$result"; /*$query = 'SELECT * FROM upload2 ';//ORDER BY entry_ID DESC if ($r = mysql_query ($query)) { while ($row = mysql_fetch_array ($r)) { print "<p>{$row['id']}<br/> {$row['name']}<br/> {$row['type']}<br/> {$row['size']}<br/> {$row['path']}<br/> </p>"; } }*/ mysql_close();?>[/code][b]I have commented out some stuff I've tried but the query ran from the sql console returns the correct value but when it is ran through php, the wrong stuff is output...Cheers[/b] Quote Link to comment https://forums.phpfreaks.com/topic/20634-writing-to-db-my-slashes-disappear/#findComment-91175 Share on other sites More sharing options...
kenrbnsn Posted September 13, 2006 Share Posted September 13, 2006 Your backslash problem occurs because the backslash is the escape character in PHP & MySQL and when you're string is inserted into the DB, MySQL sees the backslash and removes it. You can either double the backslashes in the original string[code]<?php $str = "C:\\new\\folder\\filename.ext" ?>[/code]or use forward slashes, which work just as well:[code]<?php $str = "C:/new/folder/filename.ext" ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/20634-writing-to-db-my-slashes-disappear/#findComment-91296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.