How to store a file path in MySQL?

I know this must be very simple, but I cannot make this work - I am trying to store a simple file path in a MySQL database from my PHP web page. But the backslashes get lost when I write the update statement (it's an existing record).

$sPath = "c:\\mypath\myfile.jpg";
$sSQL = "UPDATE mytable SET filepath='" . $sPath . "' WHERE id = 9";

I end up with a filepath that is c:mypathmyfile.jpg

If I first call addslashes($sPath) then I end up with double the slashes in the database.

Can someone help this poor soul? :)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to escape the backslashes with an extra '\' if my memory serves me right.
Dave BaldwinFixer of ProblemsCommented:
I think you should use addslashes() end up with double slashes in the database.  Then when you retrieve the data, run it thru stripslashes() to get rid of them.  I have lot of PHP pages doing that.
Or use mysql_real_escape_string()


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
seems like you are missing a slash on your second set of backslashes

$sPath = "c:\\mypath\myfile.jpg"; should be $sPath = "c:\\mypath\\myfile.jpg";

If you double backslash like this then you don't need to use the add Slashes method
rascalAuthor Commented:
thanks everyone!

the solution was to use the mysql_real_escape_string()
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.