cyclefiend2000 wrote:the echo's that i have already built in show correctly.
i want most of the data to be the same for all people just the variables you point out should vary.
i am getting extra rows inserted into my database.
the data is all either null or zero on these rows.
this means that there are NULL or 0 values
in those arrays you use:
arrays: $employee $hours $chief
or if you mean other values those variables also are NULL or 0
I cant understand this, as the code you show probably is not the cause.
What I see your code should work ..if it get correct data to insert.
You can connect to db ONCE before the loop and close it after loop
... but this is another detail which will not answer your question
$connection = mysql_connect($host,$user,$password)
or die ("Could not connect to server");
$db = mysql_select_db($database,$connection)
or die ("Could not select database");
for ($n=0;$n<=3;$n+=1){
if ($employee[$n]!="none"){
echo $employee[$n]." - ";
echo $hours[$n]." hours <br>";
echo "Crew Chief: ".$chief[$n]."<br>";
$cchief=$chief[$n];
$employee_insert=$employee[$n];
$hours_insert=$hours[$n];
$query = "INSERT INTO survey
(input_date,projectname,projectnumber,employee,hours,
code,codedescription,description,weather,day,crewchief)
VALUES('$insert_date','$job[1]','$job[0]','$employee_insert','$hours_insert',
'$code','$code_description','$description','$weather','$day','$cchief')";
$result = mysql_query($query)
or die ("Could not execute query");
}
}
mysql_close($connection);