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

Edited by php-coder
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.