I am working on a form that has a couple of different arrays. There is the company info, the attendee info and the spouse info. I am able to enter data into the form and it responds by telling me I am registered and I do receive an e-mail confirmation. However, the email tells me I have 0 attendees and 0 spouses. The data is not inserted into the tables.

<?php
include_once "connection.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
// form has been submitted, create variables with POST array
if($_GET[act] == "sub") {
      $company = $_POST[company];
      $address = $_POST[address];
      $city = $_POST[city];
      $state = $_POST[state];
      $zip = $_POST[zip];
      $contact = $_POST[contact];
      $phone = $_POST[phone];
      $email = $_POST[email];
      mysql_query("INSERT INTO zone5_company (company, address, city, state, zip, contact, phone, email, date) VALUES '$company', '$address', '$city', '$state', '$zip', '$contact', '$phone', '$email' CURDATE())");
// get value from previous insert operation, zone5_company
$tid = mysql_insert_id();
// insert attendee info into zone5_attendee table
$attendeeQuery = "INSERT INTO zone5_attendees (id, attendee_name, company)VALUES";
for ($j=1; $j<=20; $j++) {
	$count=0;
	// if the attendee_name is not empty
	if ($_POST['attendee_name' . $j] != "") {
		if ($j != 1) {
			$attendeeQuery .= ",";
	}
	$attendeeQuery .= "('" . $_POST['attendee_name' . $j] . "','" . $tid . "')";
	$count++;
	}
}
// insert spouse info into zone5_spouses table
$spouseQuery = "INSERT INTO zone5_spouses (id, spouse_name, company)VALUES";
for ($j=1; $j<=10; $j++) {
	$count2=0;
	if ($_POST['spouse_name' . $j] != "") {
		if ($j != 1) {
			$spouseQuery.= ",";
	}
	$spouseQuery .= "('" . $_POST['spouse_name' . $j] . "','" . $tid . "')";
	$count2++;
	}
}
mysql_query($attendeeQuery);
mysql_query($spouseQuery);

// e-mail to 
// compose e-mail
$to = "a@aaaaaaa.com"; // owner's email address
$subject = "New Zone 5 Registration Form";
$headers = "From: $company <$email>";
$body = "A new Zone 5 Registration Form has been submitted by $company\n";
$body .= "with $count attendee(s) and $count2 spouse(s).\n\n";
// send the email
mail($to, $subject, $body, $headers);
// e-mail to attendee
// compose e-mail
$to = "$email"; // contact at company email
$subject - "Received Your Zone 5 Registration";
$body = "Thank you for your zone 5 registration. This is your confirmation.\n\n";
$body .= "Fair, Festival or Association: $company\n";
$body .= "$address\n";
$body .= "$city, $state $zip\n";
$body .= "Your registration is for $count attendees and $count2 spouses\n\n";
$attendees = mysql_query("SELECT company from zone5_company ORDER by id ASC");
$attendeeArray = array();
$attendeeArray[0] = "n/a";
while ($thisCompany = mysql_fetch_object($attendees)) {
	array_push($attendeeArray, $thisCompany->company);
}
for($k=1; $k<=20; $k++) {
	if($_POST['attendee_name' . $k] != "" ) {
		$body .= $_POST['attendee_name'. $k] . "\n\n";
	}
}
//send
mail($to, $subject, $body, $headers);
header("location: $PHP_SELF?act=done");
}
?>
<head>
<title>$sitename</title>
<link href="page.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="form_style.css" />
<link href="header.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/swfobject.js"></script>
</head>
<body>
<?php
if($_GET[act] == "done") {
?>
We have received your registration. Thank you for entering online.
<?php
} else {
?>
<h2>2008 Zone 5 Conference Registration Form</h2>
<p>Membership to the IAFE is not required to attend this conference. Registration fees are $70 per attendee for registrations 

received prior to February 1. Beginning February 1, the registration fee is $95 per attendee.</p>
<p>Lodging is not included in the registration fee. Call the Grand Prairie Hotel at 866-577-7527 to secure lodging for the 

Zone 5 Conference.</p>
<form action="<?PHP_SELF ?>?act=sub" method="post" name="zone5" >
<fieldset>
<legend>Fair, Festival or Business Information</legend>
<p>
<label for="name">Fair, Festival or Business Name</label>
<input type="text" id="company" id="company" />
<br />
<label for="address">Address</label>
<input type="text" id="address" name="address" />
<br />
<label for ="city">City</label>
<input type="text" id="city" name="city" />
<br />
<label for="state">State</label>
<input type="text" id="state" name="state" />
<br />
<label for="zip">Zip Code</label>
<input type="text" id="zip" name="zip" />
<br />
<label for="contact">Contact</label>
<input type="text" id="contact" name="contact" />
<br />
<label for="phone">Phone</label>
<input type="text" id="phone" name="phone" />
<br />
<label for="email">E-mail address</label>
<input type="text" id="email" name="email" />
</p>
</fieldset>
<fieldset>
<legend>Attendee Information</legend>
<p>Enter the name(s) of the person(s) that will be attending the Zone 5 Conference. <br /><br />
<?php
for($i=1; $i<=20; $i++) {
?>
<label for="attendee_name . <?php echo $i; ?>">Attendee Name</label>
<input type="text" id="attendee_name . <?php echo $i; ?>" name="attendee_name . <?php echo $i; ?>" />
<br />
<?php
} 
?>
</p>
</fieldset>
<fieldset>
<legend>Spouse Program Participants</legend>
<p>Enter the name(s) of the spouse(s) that will be participating in the Zone 5 Spouse Program. <br /><br />
<?php
for($i=1; $i<=10; $i++) {
?>
<label for="spouse_name . <?php echo $i; ?>">Spouse Name</label>
<input type="text" id="spouse_name . <?php echo $i; ?>" name="spouse_name . <?php echo $i; ?>" />
<br />
<?php
}
?>
</p>
</fieldset>
<fieldset>
<legend>Special Accommodation Needs</legend>
<p>
<label for="special">Special accommodatons required (dietary, etc)</label>
<input type="text" id="special" name="special" size="100" />
</p>
</fieldset>
<fieldset>
<legend>Payment</legend>
<p>
<input type="radio" id="pmtMethod" name="pmtMethod" value="credit" checked="checked" />
Online with Credit Card<br />
<input type="radio" id="pmtMethod" name="pmtMethod" value="check" />
Check by Mail
</p>
</fieldset>
<p><input type="submit" value="Submit" /></p>
</form>
<?php
}
?>
<?php
include "footer.php";
?>
</body>
</html>

    Have you checked to see if your INSERT queries are throwing an error?
    Change

    mysql_query($attendeeQuery);
    mysql_query($spouseQuery);
    

    to

    mysql_query($attendeeQuery) or die(mysql_error());
    mysql_query($spouseQuery) or die(mysql_error());
    

    That might help.

    btw, I hope this is not production code. It's a very bad idea to insert data from outside PHP (i.e. $_POST data) directly into database queries. You should always clean your data before inserting it into any queries.

      I didn't. The code you provided gives me the following error:

      You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.

      What should I look for?

        you can try manually inserting to the mysql database - for example, if you are using phpmyadmin, when you are at the site to manage your table, click "insert". you can maunally insert something and it will tell you the code it used to insert. check and see the differences.

          Try echoing out the query that fails so you can see what's happening. A combination of that and the SQL error is usually enough to diagnose the problem.

            Write a Reply...