Hidden Characters in String ruining SQL statement (php, mysql) -
i have variable appending sql statement, there seem hidden characters causing errors.
i have $addtoinventory variable number (e.g. 405,000). i'm trying following snippet of code rid myself of characters when echo still see \0\0\0\0 (null) after number.
$addtoinventory= str_replace(",", "", $pieces[1]); $addtoinventory= str_replace("\r", "", $addtoinventory); $addtoinventory= str_replace("\n", "",$addtoinventory); $addtoinventory = preg_replace('/^[\pz\pc]+|[\pz\pc]+$/u', '', mysql_real_escape_string($addtoinventory)); $sql_query = "update products set products_quantity = " .$addtoinventory." products_model '$code'";
echoing $sql_query produces:
update products set products_quantity = 405000\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 products_model '111'.
use trim()
. removes nul-bytecharacters.
this function returns string whitespace stripped beginning , end of str. without second parameter, trim() strip these characters:
- " " (ascii 32 (0x20)), ordinary space.
- "\t" (ascii 9 (0x09)), tab.
- "\n" (ascii 10 (0x0a)), new line (line feed).
- "\r" (ascii 13 (0x0d)), carriage return.
- "\0" (ascii 0 (0x00)), nul-byte.
- "\x0b" (ascii 11 (0x0b)), vertical tab.
$addtoinventory= str_replace(",", "", $pieces[1]); $addtoinventory= trim($addtoinventory);
Comments
Post a Comment