colap Posted October 16, 2012 Share Posted October 16, 2012 (edited) "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 October 16, 2012 by php-coder Quote Link to comment Share on other sites More sharing options...
requinix Posted October 16, 2012 Share Posted October 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
colap Posted October 16, 2012 Author Share Posted October 16, 2012 How can i insert string with starting and ending double quoutes? Quote Link to comment Share on other sites More sharing options...
trq Posted October 16, 2012 Share Posted October 16, 2012 There is nothing particularly special about it. Just escape your data as per usual. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 16, 2012 Share Posted October 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 16, 2012 Share Posted October 16, 2012 How can i insert string with starting and ending double quoutes? fgetcsv() will leave the quotes out automatically - they won't be in the values you get back. Quote Link to comment Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 to insert string with double quotes and single quotes in mysql tables use mysql_real_escape_string(); example : $variable = mysql_real_escape_string($variable); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.