Click here to Skip to main content
15,887,746 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: MySQL syntax error near '' Pin
Geoff Williams25-Oct-10 22:28
Geoff Williams25-Oct-10 22:28 
GeneralRe: MySQL syntax error near '' Pin
Gerben Jongerius26-Oct-10 1:08
Gerben Jongerius26-Oct-10 1:08 
GeneralRe: MySQL syntax error near '' Pin
nathionice26-Oct-10 1:55
nathionice26-Oct-10 1:55 
GeneralRe: MySQL syntax error near '' Pin
Gerben Jongerius26-Oct-10 3:36
Gerben Jongerius26-Oct-10 3:36 
GeneralRe: MySQL syntax error near '' Pin
nathionice26-Oct-10 5:00
nathionice26-Oct-10 5:00 
GeneralRe: MySQL syntax error near '' Pin
Gerben Jongerius26-Oct-10 20:34
Gerben Jongerius26-Oct-10 20:34 
AnswerRe: MySQL syntax error near '' Pin
Graham Breach26-Oct-10 2:57
Graham Breach26-Oct-10 2:57 
AnswerRe: MySQL syntax error near '' Pin
cjoki26-Oct-10 5:04
cjoki26-Oct-10 5:04 
I have used used loops to make a multiple insert query like above but form a tad different. I suspect the issue is in the query contruction itself.

Also why are you reassigning the $c variable with every loop of the for? This will slow down your code.

I guess the $headerTable is an single diminsional array? Currious why you did not use a multi-diminsional array...?

It looks like you are skipping 6 rows at a time...so looking at your error message if the values are all of the correct type (they are all varchar or similar?) then it looks like there maybe a second row starting

...
VALUES('SOF','1','1500','19970519','112904','1 '),
...

note the comma on the end there.

also
...
MySQL server version for the right syntax to use near ''
...
I suspect you may have a extra line of data in the array with an empty row sent to your function

Can you post the $query when you echo it? You should be able to copy and past it into the mysql admin tool, phpmyadmin, or other system that will let you run the query inside the tool. although I suspect you will see the same error.

btw I would write this function like this...

<?php
	WriteArrayToHeaderDatabase($headerTable,$table);
	function WriteArrayToHeaderDatabase($headerTable,$table)//Pass which table am i writing to
	{
		//I do the connecting to database here which is fine the problem is below
		$query = "INSERT INTO ".$table."(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES";
		
		$c = count($headerTable);
		echo "headerTable Count = ".$c;
		for($i = 0; $i < $c; $i += 6) 
		{
			// Add the next batch of values to the query string
			if($i==0)
			{
				$query.= "('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
			}
			else
			{
				$query.= ", ('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
			}
			echo $query; 
			$result = mysql_query($query) or die('Query failed: ' . mysql_error());			
		}
		return true;
	}
?>


this will run faster and is easier to read. It will also tell you how many rows are in the array sent to your variable.
GeneralRe: MySQL syntax error near '' Pin
nathionice26-Oct-10 5:42
nathionice26-Oct-10 5:42 
GeneralRe: MySQL syntax error near '' Pin
Gerben Jongerius26-Oct-10 20:29
Gerben Jongerius26-Oct-10 20:29 
GeneralRe: MySQL syntax error near '' Pin
nathionice26-Oct-10 20:53
nathionice26-Oct-10 20:53 
GeneralRe: MySQL syntax error near '' Pin
cjoki27-Oct-10 5:50
cjoki27-Oct-10 5:50 
Questionhello about Cacti Pin
lxlenovostar19-Oct-10 2:38
lxlenovostar19-Oct-10 2:38 
AnswerRe: hello about Cacti Pin
cjoki19-Oct-10 4:39
cjoki19-Oct-10 4:39 
Questioni catch a problem when i compiling Pin
lxlenovostar18-Oct-10 3:03
lxlenovostar18-Oct-10 3:03 
AnswerRe: i catch a problem when i compiling Pin
Iranian MM8-Sep-11 5:30
Iranian MM8-Sep-11 5:30 
Questionproblem in windows 7 Pin
mstanwar13-Oct-10 14:46
mstanwar13-Oct-10 14:46 
AnswerRe: problem in windows 7 Pin
Mohamed7IBrahim18-Nov-10 3:48
Mohamed7IBrahim18-Nov-10 3:48 
GeneralRe: problem in windows 7 Pin
Ali Al Omairi(Abu AlHassan)13-Feb-11 14:50
professionalAli Al Omairi(Abu AlHassan)13-Feb-11 14:50 
QuestionPHP File Open and Reading character by character Pin
nathionice13-Oct-10 5:33
nathionice13-Oct-10 5:33 
AnswerRe: PHP File Open and Reading character by character Pin
cjoki14-Oct-10 4:44
cjoki14-Oct-10 4:44 
RantRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 0:59
Macotti20-Oct-10 0:59 
GeneralRe: PHP File Open and Reading character by character Pin
cjoki20-Oct-10 5:00
cjoki20-Oct-10 5:00 
RantRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 15:45
Macotti20-Oct-10 15:45 
GeneralRe: PHP File Open and Reading character by character Pin
cjoki21-Oct-10 7:38
cjoki21-Oct-10 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.