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

Linux, Apache, MySQL, PHP

 
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 
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 
Sorry I gave you a bad example as stated above (thanks, Gerben Jongerius for pointing that out).... the mysql_query needs to be outside the loop. To be accurate this is how that should be set up...


$query = "INSERT INTO ".$table."(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES";
$c = count($headerTable)-1; //<-- not sure about this....
echo "headerTable Count = ".$c;
$numberOfLoops=0;
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;
echo 'The number of loops';	
echo $numberOfLoops++;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
return true;
}



if you do not move it outside the loop then when you have more than one set of six records to process you will generate a bad query on the second pass.

if example what you currently have one the first pass will produce a query that looks like this on the first pass;
INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 ')

and on the second pass;
INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 '), ('','','','','','')

this has 2 errors, one is the duplucate data being entered into the table and the other is the empty data on the second pass.

If you move the mysql_query to outside of the loop you would get one insert like this;
INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 '), ('','','','','','')

That will take care of the duplcate data issue. To fix the blank data look at your data source. Something is wrong with it adding an extra line as your output shows;
headerTable Count = 7
so one extra row is being added to your data source before it hits this function, this should be looked at.

Hope this helps
Chris J
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 
AnswerRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 1:07
Macotti20-Oct-10 1:07 
AnswerRe: PHP File Open and Reading character by character Pin
solarpowerlightssource22-Oct-10 12:21
solarpowerlightssource22-Oct-10 12:21 
QuestionLogin and registration system using php Pin
Shamol-nahid11-Oct-10 14:24
Shamol-nahid11-Oct-10 14:24 
AnswerRe: Login and registration system using php [modified] Pin
Karthik. A11-Oct-10 15:06
Karthik. A11-Oct-10 15:06 

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.