[Phpug] Help Please?????
Tony Freegrove
tonyf at southeastpromotions.com
Fri Dec 14 07:16:27 GMT 2007
Hi everyone,
I've been on this list for a while, but never subscribed before. I've only
recently started using PHP/MySQL and have come up with a problem, that I
can't seem to answer myself from the web or books etc so it's time to ask
the experts. Here goes
I've built a page that retrieves data from a table,
Once the data is retrieved, I've built an array called $defects that only
contains the information I want to insert into another table. This data is
then populates a form on the page I want to display. I've built the HTML
table using a "foreach" statement and an "if" statement to ignore any empty
data fields. (so far so good)
However, here's where it gets complicated - I want the user to be able to
assign each field to a category and update that information to a table. At
the moment, I've included the "INSERT" statement as part of the "foreach"
statement. When the user clicks on "submit" the page only inserts the last
entry. If there are three items in the table, it will insert the last one 3
times. I can't figure out how to make it loop through the array entries and
do and "INSERT" for each one.
The specific code I'm having the problem with is below. Have I left
something glaringly obvious out????
Thanks in advance for any help on this.
<?
foreach($defects as $key => $value){
$key++;
if ($value!=""){
print "<tr><td colspan='2'><input name='defect' type='hidden'
value='$value'>$value</td><td colspan='2'><select name='assign'
id='assign'><option value='estates'>Estates</option><option
value='fieldops'>Field Ops</option><option
value='contractor'>Contractor</option><option
value='misc'>Miscellaneous</option><option value='nfa'>No Further
Action</option><option value='close'>Close</option></select><br
/></td></tr>";
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO estates (siteref, sitename, `date`,
engineer, defect, assigned) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['siteref'], "text"),
GetSQLValueString($_POST['sitename'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['engineer'], "text"),
GetSQLValueString($_POST['defect'], "text"),
GetSQLValueString($_POST['assign'], "text"));
mysql_select_db($database_connaiep, $connaiep);
$Result1 = mysql_query($insertSQL, $connaiep) or die(mysql_error());
}
}
}
?>
Regards,
Tony Freegrove,
South East Promotions Limited,
Tingar,
Ballygarrett,
Gorey,
Co. Wexford,
Ireland.
Tel.:+353 53 948 2619
Mobile: + 353 87 979 1614
More information about the Phpug
mailing list