Jump to content

apostrophe problem


vj5

Recommended Posts

I am having problem inserting data to mysql with apostrophe. For example, if groupname has something like Gene's Bakery, apostrophe 's with bakery is cutting off while inserting into mysql. here is my code:

$QRY = "INSERT INTO `tablename` (   `groupname`,   `provider`)	Values (".dbNull($cgroupname).", "	   .dbNull($cprovider).")";$result = mysql_query($QRY);

dbnull is a function call . Here is the code for that:

function dbNull($str){	if (!isset($str) || $str==NULL)		return 'null';	else return "'". mysql_real_escape_string(trim($str)) . "'";}can someone please help with this problem?

Link to comment
Share on other sites

No no... $QRY. The variable itself, not the result casting a query with it.See what do you get with

$QRY = "INSERT INTO `tablename` (   `groupname`,   `provider`)	Values (".dbNull($cgroupname).", "	   .dbNull($cprovider).")";var_dump($QRY);//$result = mysql_query($QRY);

And begin debugging from there. There's an apostrophe that needs escaping somewhere, yet the escaping must be done in a way that would work in all cases, not just this one. The only way this can be achieved is by carefully examining the query you'll be giving to MySQL before you give it to it.

Link to comment
Share on other sites

No no... $QRY. The variable itself, not the result casting a query with it.See what do you get with
$QRY = "INSERT INTO `tablename` (   `groupname`,   `provider`)	Values (".dbNull($cgroupname).", "	   .dbNull($cprovider).")";var_dump($QRY);//$result = mysql_query($QRY);

And begin debugging from there. There's an apostrophe that needs escaping somewhere, yet the escaping must be done in a way that would work in all cases, not just this one. The only way this can be achieved is by carefully examining the query you'll be giving to MySQL before you give it to it.

I used var_dump($ORY) and commented out the $result.....This is what I get:
string(431) "INSERT INTO `tablename` ( `dosstart`, `dosend`, `provider`, `member`, `brokerid`, `description`, `date`, `status`, `time`, `claimid`, `fup_date`, `carrier`, `group_name`, `group_number`, `subscriber`, `rep`) VALUES (null, null, 'p', 'm', 'demobroker', 'test', '20080416', 'pend', '094743', '155', '20080430', 'carrier', 'Gena', '99997', 's', 'john doe')"

Link to comment
Share on other sites

Next steps in self debugging :) .What values do $cgroupname and $cprovider have before being submitted to dbNull()? var_dump() them too to find out.Are the values of $cgroupname and $cprovider what you expected them to be? If not, then show us some more code from the top, and also try to debug the problem yourself by tracking how the submitted value changes during validation and all.If the values are correct, what would you expect the value of $QRY to be?If your expected value is different, then the problem must be lying somewhere in the dbNull() function.

Link to comment
Share on other sites

Next steps in self debugging :) .What values do $cgroupname and $cprovider have before being submitted to dbNull()? var_dump() them too to find out.Are the values of $cgroupname and $cprovider what you expected them to be? If not, then show us some more code from the top, and also try to debug the problem yourself by tracking how the submitted value changes during validation and all.If the values are correct, what would you expect the value of $QRY to be?If your expected value is different, then the problem must be lying somewhere in the dbNull() function.
When I var_dump ($cgroup_name), I get "Gene".
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...