Re: PHP MySQL insert

From: Date: Thu, 18 Aug 2005 17:08:03 +0000
Subject: Re: PHP MySQL insert
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-220887@lists.php.net to get a copy of this message
"Jon" <jonraston@hotmail.com> wrote in message news:A4.E7.33075.0CDB4034@pb1.pair.com... > Please help with an insert problem. > > Sometimes $data1 could have a comma and that messes up the insert. how do > I > get around that? > > $query = "insert into testtable6 (indx, col1, col2) values (NULL, > '$data1', > '$data2')"; > mysql_db_query("testdb", $query); You are looking for the "addslashes" function. It prepares data for database querys: $query = "insert into testtable6 (indx, col1, col2)"; $query .= " values (NULL, '" . addslashed($data1) . "'"; $query .= ",'" . addslashed($data2) . "'"; mysql_db_query("testdb", $query); Also, you will need to use the "removeslashes" function when you get data from a query. DanB

« previous php.general (#220887) next »