Click to See Complete Forum and Search --> : name problem, inserting


ripken204
03-30-2007, 10:39 AM
i have a csv file that im pulling alot of info from and inserting it into a mysql database through the use of php. it pulls the info out using this command

list($lastName) = split('[;]', $buffer[0]);

i have alot more variable than $lastName but $lastName is what i have the problem with. when i go to insert it into the DB is gives me an error saying im using the wrong syntax for a specific entry. it turn out that the last name is O'Neal. there is a ' in the last name... how exactly can i fix this, i cant put quotes around the variable as it will give me an error about using quotes..

ripken204
03-30-2007, 11:21 AM
if i do this

\"$lastName\"

it will at least import the name, but it will output it as O\'Neal

mattyblah
03-30-2007, 02:54 PM
I think you're looking for the function mysql_real_escape_string or mysql_escape_string. Try looking those up.

ripken204
03-30-2007, 11:09 PM
mysql_real_escape_string worked perfectly, thx