overlordofevil Posted February 1, 2010 Share Posted February 1, 2010 Hello all, I am having a minor issue with my scripts when I have php pull data from mysql. Some times data put into the table have ' or " included in the text. So when php pulls that data and I include the variable I get a php error check the manual message. example: I am working with names the the following names are put in the table John Mike Joshua M'ekal So I am workign with the data and I need to add a note to the system that includes the names so I have something like this. $note = "order was updated for $name"; I then insert this into the table. Everything works just fine until it gets to the last name in the list. Then I get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ekal')' at line 1 So what I am wondering is there a way to turn the variable into a string so the ' stops kicking out this error anytime I try to insert it into a table? Any info or suggestions would be appreciated. Thanks Bill Link to comment https://forums.phpfreaks.com/topic/190540-data-error-question/ Share on other sites More sharing options...
jl5501 Posted February 1, 2010 Share Posted February 1, 2010 the problem is the apostrophe in the name in $name so if you use $note = "order was updated for". mysql_real_escape_string($name); all will be well Link to comment https://forums.phpfreaks.com/topic/190540-data-error-question/#findComment-1004993 Share on other sites More sharing options...
taquitosensei Posted February 1, 2010 Share Posted February 1, 2010 mysql_real_escape_string $note=mysql_real_escape_string("order was updated for $name"); Link to comment https://forums.phpfreaks.com/topic/190540-data-error-question/#findComment-1004994 Share on other sites More sharing options...
overlordofevil Posted February 3, 2010 Author Share Posted February 3, 2010 cool thanks for the info I will try that out. Link to comment https://forums.phpfreaks.com/topic/190540-data-error-question/#findComment-1006238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.