473,788 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

apostrophe breaking an insert query from import csv file

170 New Member
Hi all,

I have the code:

Expand|Select|Wrap|Line Numbers
  1. if(is_uploaded_file($_FILES['file']['tmp_name'])) 
  2.     {
  3.     move_uploaded_file($_FILES['file']['tmp_name'],$_FILES['file']['name']);
  4.     }
  5.  
  6. $fcontents = file ('students.csv'); 
  7. $size=sizeof($fcontents);
  8. for($i=0; $i<sizeof($fcontents); $i++) 
  9.     { 
  10.     $line = trim($fcontents[$i]); 
  11.     $arr = explode(",", $line); 
  12.  
  13.     $sql = "insert into staffcba_students values ('','$user','$pass','$classyear','$classname','$classid','".implode("','",$arr)."')"; 
  14.     mysql_query($sql);
  15.  
  16.     if(mysql_error()) 
  17.         {
  18.         echo mysql_error() ."<br>\n";
  19.               } 
  20.     }
  21.  
The csv file looks like

Peter,Porridge, M
Ethel,Elephant, F

All works perfectly until one of the names has an apostrophe

Eg.
Peter,O'Toole,M

Now I can see why it's breaking it. But I'm not sure how to fix the problem.

I tried addslashes around the trim($fcontents[$i]), but to no avail. Can anyone suggest a simple solution?
Dec 5 '07 #1
1 2795
stepterr
157 New Member
Take a look at the get_magic_quote s_gpc function. I think that may solve your problem. Link
Dec 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7984
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes right. i get all types of errors no matter what i try. i get "missing right quote", "invalid token" etc. i've tried using QuotedStr and nothing works. here is my current attempt in which i get an "invalid use of keyword. token: n'%'" sSQL :=...
16
17020
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
13
11440
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices Restaurant" etc. automatically and programmatically during data entry? This would eliminate my concatinated strings from producing errors when I base the string on a query. Think this is an example of the "Dreaded Apostrophe Bug." If I enter a...
1
5376
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than import in excel to get rid of the apostrophe. It has been happen about two months now before it didn't do that. It is only happen when I have text data type in the table. If I change to number data type then the problem go away but most of my...
9
6896
by: dajava | last post by:
Hi, Sorry for this beginner's question. I do not know PHP and write for my friend. He has never been a professional programmer. He studied C and PHP with some books and made a bulletin board for his hobby homepage. (He uses MS-Windows XP)
12
4168
by: Johnny BeGood | last post by:
Hi All, When a user enters an Apostrophe into a text area field on a form, i.e. didn't, it mucks with odbc as follows Syntax error (missing operator) in query expression ''didn't', Whats the best way to handle this, other than not entering the apostrophe. I'm stuck with the current backend database as its part of an existing
8
6493
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into usable data using more code. The problem I have is that the conversion of the text file, using a...
2
3334
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a property IssueData. this property exist in SimpleBean which create a connection from DB and insert the data. At run time servlet and server also show that loggging are saved in DB. But when I open the table in Access. Its empty. Ms-Access have...
1
2218
by: ArizonaJohn | last post by:
Hello, The query below works if $find is just a regular word with no special characters, and it even works if $find has a "%" in it or a "&". However, it does not work if $find has an apostrophe in it. Any ideas on how I can change the code to make it work if $find has an apostrophe in it? Thanks in advance, John
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.