473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Apparently an error in syntax

170 100+
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 1430
ronverdonk
4,258 Expert 4TB
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
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...
12
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...
1
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...
0
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...
5
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",...
3
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...
9
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;" ...
25
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...
15
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...

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.