473,946 Members | 15,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apparently an error in syntax

170 New Member
Could someone please tell me what's wrong with the code below. It worked fine the first time, then I cleared the table (results) and tried it again, but got the message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1".

Problem is I can't see any " near line. And it worked fine the first time. What am I missing?

Thankyou.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include("config.php");
  4. include("opendb.php");
  5.  
  6.   $fcontents = file ('mysqldata.csv'); 
  7.  
  8.   for($i=0; $i<sizeof($fcontents); $i++) { 
  9.       $line = trim($fcontents[$i]); 
  10.       $arr = explode(",", $line); 
  11.  
  12.       $sql = "insert into results values ('','". 
  13.                   implode("','", $arr) ."')"; 
  14.       mysql_query($sql);
  15.  
  16.       if(mysql_error()) {
  17.          echo mysql_error() ."<br>\n";
  18.       } 
  19. }
  20. ?>
  21.  
Nov 27 '06 #1
1 1459
ronverdonk
4,258 Recognized Expert Specialist
Looks fine to me. To make sure I made this little test to see the results.[php]<?php
$arr = array("a", "b", "c");
$sql = "insert into results values ('','".
implode("','", $arr) ."')";
echo "1. $sql<br />";
$sql = "insert into results values ('','".
implode(',', $arr) ."')";
echo "2. $sql<br />";
$arr = array("a'", "b", "c");
$sql = "insert into results values ('','".
implode("','", $arr) ."')";
echo "3. $sql<br />";
?>[/php]
and the results were:[php]1. insert into results values ('','a','b','c' )
2. insert into results values ('','a,b,c')
3. insert into results values ('','a'','b','c ')

[/php]
Now 1 and 2 are fine, but inserting a quote in the array produces result 3 and makes the sql statement invalid. Echo your array content and see if that is the case here.

Ronald :cool:
Nov 27 '06 #2

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

Similar topics

2
4405
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
12
3965
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with both single quotes and no single quotes, but it doesn't work either way. What am I doing wrong? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById('weblogs').style.visibility='hidden';
1
7518
by: Minh | last post by:
I've just installed VS.NET 2003 on my Athlon XP 1800+. However I couldn't get any project with STL includes to compile even if I create a new empty project (and added #include <string>). It gave me a bunch of "missing ;" errors. I did reinstall the whole thing a few times but it didn't work. Anyone have any idea? Thanks c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(862) :
0
1420
by: Shashikiran Prabhakar via .NET 247 | last post by:
(Type your message here) Hi, I am not very conversent in VC++, but the requirement for me is to run a rendering code. However i am encountering the following errors. c:\Program Files\MultiGen-Paradigm\include\vsg\stlport\cstdio(49): error C2039: '_vsnprintf' : is not a member of 'std' c:\Program Files\MultiGen-Paradigm\include\vsg\stlport\cstdio(115): error C2039: 'vsnprintf' : is not a member of 'std' c:\Program...
5
1195
by: Haydnw | last post by:
I have the following line of code in a code-behind file. It's part of a event which is run when a user clicks an asp:imagebutton on a page. tblMainImage.Rows.Cells.Attributes.Add("background", "../images/albums/" & Request.QueryString("d") & "/" & RowView("strFilename") & ".jpg") However, when I view the page I get an error message with this line highlighted, saying:
3
16279
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
9
1151
by: Kerem Gümrükcü | last post by:
Hi, i am gettin this compiler error over and over for AFIAK perfectly clean code: error C2143: Syntaxerror : Missing ';' before ']' for the Line with the " char szMultibyteString;" //CODE-------------------
25
4043
by: notahipee | last post by:
I have been trying to cin an number from 0 to 9 with a leading 0. For example 00 or 07. I was using a switch case. switch (int) { case 01: break; case 02: break;..... My problem arises at 08 and 09 because they are not octal. Is there any way to coerce the input variable to decimal despite it having a leading zero .
15
5713
by: madhu.ab | last post by:
Hi All, I am getting the following errors when i am including header file winuser.h I dont know whats happening. How will an error occur in winuser.h?? Please help. \microsoft visual studio\vc98\include\winuser.h(39) : error C2061: syntax error : identifier 'HDWP'
0
10150
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11141
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
11324
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
10679
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...
0
9873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7403
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
6318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4928
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
4524
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.