|
Posted by moosus on 06/01/06 23:51
G'day All,
I'm not sure if the subject line says it correctly, but what I am doing is
collecting company details and up to 10 associated names.
I then want to put these into a table with a new line for each name but also
have the company details on that line
Eg Form >
Company Name
Company Phone Number
Company Address
Name1
Name2
Name3
Eg DB TABLE >
Company Name | Company Phone | Company Address | Name 1
Company Name | Company Phone | Company Address | Name 2
Company Name | Company Phone | Company Address | Name 3
So my thoughts were to process all the names out of the form into a $name[]
And then use a foreach {} to loop through the set and run the query inside
the loop - it works when printed to screen but not when entering into DB
I think there is a problem with my SQL not "knowing" what array variable to
use ... But I am a bit lost
If anybody could help I would appreciate it.
Cheers
moosus
============================================ CODE
// make array of contacts
$name[1]= strip_tags($_POST['n1']);
$name[2]= strip_tags($_POST['n2']);
$name[3]= strip_tags($_POST['n3']);
$name[4]= strip_tags($_POST['n4']);
$name[5]= strip_tags($_POST['n5']);
$name[6]= strip_tags($_POST['n6']);
$name[7]= strip_tags($_POST['n7']);
$name[8]= strip_tags($_POST['n8']);
$name[9]= strip_tags($_POST['n9']);
$name[10]= strip_tags($_POST['n10']);
//make array of total charge so it is only displayed on the primary
record
$totalcharge[1]= $total;
require_once('dbc.php'); //Connect to db
//Define Query Rego
$registration = "INSERT INTO afta
(
id,
name,
phone,
email,
company,
street,
suburb,
state,
postcode,
country,
cphone,
cfax,
industrytype,
affiliation,
rego,
expiry,
totalcharge
)
VALUES
(
'',
'$value',
'{$_POST['phone1']}',
'{$_POST['em1']}',
'{$_POST['companyname']}',
'{$_POST['street']}',
'{$_POST['suburb']}',
'{$_POST['state']}',
'{$_POST['postcode']}',
'{$_POST['country']}',
'{$_POST['phone']}',
'{$_POST['fax']}',
'{$_POST['industry']}',
'{$_POST['affiliation']}',
'{$_POST['rego']}',
'$expiry',
'$totalcharge[$key]'
)";
// Loop through name array
foreach ($name as $key => $value){
if(@mysql_query($registration)) {
//$id = mysql_insert_id();
//header("Location:print.php?id=$id");
} else {
print '<p>Could <b>NOT</b> add entry REGO because: ' .
mysql_error() . '<br />Query is: '. $rego .' </p>';
exit;
}
}
mysql_close(); //Close db connection when done
Navigation:
[Reply to this message]
|