RE: [PHP] Number Sign in String Variables

From: Date: Sat, 18 Jan 2003 01:01:45 +0000
Subject: RE: [PHP] Number Sign in String Variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132062@lists.php.net to get a copy of this message
> I have a MySQL database that includes data with the # sign in some data > fields. My PHP script pulls the data out of the database fine, but when I > got to write back to the database, I get errors because the string gets > truncated at the # sign. For example: > > $query = "INSERT INTO order_detail > SET customer_id = -1, > order_id = $order_no, > item_id = $item_id, > item_num = \"$item_num\", > unit = \"$unit\", > short_desc = \"$short_desc\", > quantity = $quantity, > wholesaler = \"$wholesaler\", > cost = $cost, > sale_price = $sale_price"; > > This statement fails if $short_desc contains a # sign. The string stops > at > the # sign, and all the subsequent fields are empty or garbage. > > None of the various resources I have looked at indicate that the # sign is > a > special character. Any suggestions? # is used to start a comment in MySQL. Show your actual code around this statement where you make your query. The only reason the data would be cut off is if MySQL is interpreting the # as the beginning of a comment. But, if that was the case, you'd have an invalid query, so it must be a combination of things. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#132062) next »