Re: [PHP-DB] Insert path string into Mysql
Don't you also have to put quotes around "localhost" in mysql_connect? Peter On Mon, 18 Nov 2002, Alan Kelly wrote: > Hi, > > I have the following code, but it doesn't works. How can I insert a path > string into a MySql Varchar cell? The result is always FALSE, but if $path > is a normal string ($path ='demo') than it works fine. > > What can I do? (I use WInXp, Apache, and Php4.2.2) > > Thanks! > > > $database="PH"; > mysql_connect(localhost,"root",""); > @mysql_select_db($database) or die( "Unable to select database"); > $path = 'c:\\demo\\' ; > $query = "insert into PH_PHOTO (PHOTO_PATH) VALUES ('$path')"; > > $result=mysql_query($query); > > mysql_close(); > ?> > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > --- Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Insert path string into Mysql
You might also want to look into using addslashes($path), especially if you're going to be accepting this path info from a text box. http://www.php.net/manual/en/function.addslashes.php > -Original Message- > From: Steve Cayford [mailto:[EMAIL PROTECTED]] > Sent: Monday, November 18, 2002 2:21 PM > To: Alan Kelly > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] Insert path string into Mysql > > > > On Monday, November 18, 2002, at 01:10 PM, Alan Kelly wrote: > > $path = 'c:\\demo\\' ; > > $query = "insert into PH_PHOTO (PHOTO_PATH) VALUES ('$path')"; > > > > $result=mysql_query($query); > > I would guess that the backslashes are being interpreted once by php > when the variable $path is interpolated into the query string (to > become c:\demo\) and again by mysql at which point it tries > to insert a > value for \d. You might try $path = 'c:demo' and see if that > works. Or maybe leave the path alone and do the query line like this: > > $query = "insert into PH_PHOTO (PHOTO_PATH) VALUES ('" . $path . "')"; > > -Steve > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Insert path string into Mysql
On Monday, November 18, 2002, at 01:10 PM, Alan Kelly wrote: $path = 'c:\\demo\\' ; $query = "insert into PH_PHOTO (PHOTO_PATH) VALUES ('$path')"; $result=mysql_query($query); I would guess that the backslashes are being interpreted once by php when the variable $path is interpolated into the query string (to become c:\demo\) and again by mysql at which point it tries to insert a value for \d. You might try $path = 'c:demo' and see if that works. Or maybe leave the path alone and do the query line like this: $query = "insert into PH_PHOTO (PHOTO_PATH) VALUES ('" . $path . "')"; -Steve -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Insert path string into Mysql
Hi, I have the following code, but it doesn't works. How can I insert a path string into a MySql Varchar cell? The result is always FALSE, but if $path is a normal string ($path ='demo') than it works fine. What can I do? (I use WInXp, Apache, and Php4.2.2) Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php