Jump to content

How Can I Insert String With Single And Double Quote Into Mysql Table?


colap

Recommended Posts

"American School, USA",School,Dot,5,,,,93.80038,10.42213,,1.207,8.4

"West Hotel, USA",Hotel,Dot,74,"West Hotel, USA",,,93.79259,10.41748,,0.668,349.9

 

 

 

How can i insert these two lines/rows into mysql table using php? I tried the addslashes function, that does the job for single quote, but how can i do the job for double quote?

 

I have tried with these php mysql functions:

mysql_connect

mysql_select_db

mysql_query

That looks like CSV data. Are you getting it from a file? Use fopen+fgetcsv+fclose to read the file line by line. The best part is that fgetcsv() will turn each line into an array according to the delimiters (ie, the commas). Assuming you know what the columns are then you can construct an INSERT based on the values in the arrays.

You should be using "MySQLI(mproved)", instead of the old and outdated "MySQL" library, first and foremost.

Secondly, the function you're looking for is named mysqli::real_escape_string (), and you can read more about it in the PHP Manual; A resource you should go through at least once.

Lastly you should really pay attention to what the people above have told you already. You will most definitely want to do some more processing on this data, not only to validate it or escape it for output, but also to ensure that it's structured properly for insertion into a database.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.