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";
mysql_query($sSQL);

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? :)

Thanks
LVL 1
rascalAsked:
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.

MaartenHensenCommented:
You need to escape the backslashes with an extra '\' if my memory serves me right.
0
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.
0
MaartenHensenCommented:
Or use mysql_real_escape_string()
http://www.php.net/manual/en/function.mysql-real-escape-string.php

Regards
0

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
moosely123Commented:
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
0
rascalAuthor Commented:
thanks everyone!

the solution was to use the mysql_real_escape_string()
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.