If someone can help me I'd be really happy. I'm still learning PHP and I've been struggling with this problem for days now.
My HTML form has a area on it that allows you to select more than one item, I want all of these items to get inserted into the db as one string (eg "Track, MTB, Cargo") and emailed as well. This is the HTML form element below.
<select size="5" name="style[]" multiple>
<option value="Track">Track</option>
<option value="Fixed">Fixed with Brake</option>
<option value="MTB">MTB/Street</option>
<option value="Road">Road</option>
<option value="Cargo">Cargo</option>
</select>
and here's my PHP Script so far (a little messy), can anyone see what I'm doing wrong and help me out?
<?
$style = $_POST['style'];
$events = $_POST['events'];
foreach($events as $eventsString)
{
}
foreach($style as $styleString)
{
}
$dbConnection = mysql_connect ("localhost", "cmwc03c_webman", "4getit")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cmwc03c_reg");
$query = "INSERT INTO event_registration(firstName, lastName, street, city, state, zip, country, company, phone, email, gender, age, teamName, food, emergencyName, emergencyPhone, nickname, years, prevTitles, events, house, style, shirt, hub, payment, special) VALUES('$firstName' , '$lastName' , '$street' , '$city' , '$state' , '$zip' , '$country' , '$company' , '$phone' , '$email' , '$gender' , '$age' , '$teamName' , '$food' , '$emergencyName' , '$emergencyPhone' , '$nickname' , '$years' , '$prevTitles' , '$eventsString' , '$house' , '$styleString' , '$shirt' , '$hub' , '$payment' , '$special' )";
$results = mysql_query($query, $dbConnection)
or die("Invalid query: " . mysql_error());
$query = "SELECT * from event_registration where FirstName ='$firstName' and LastName = '$lastName' and age = '$age'";
$results = mysql_query($query, $dbConnection)
or die("Invalid query: " . mysql_error());
$num=mysql_numrows($results);
if($num != 0)
{
$i=0;
$OrderID = mysql_result($results, $i, "OrderID");
$firstName = mysql_result($results,$i,"firstName");
$lastName = mysql_result($results,$i,"lastName");
$to = "crazycourier@hotmail.com";
//$to = "webslave@cmwc03.com";
$subject = "New Registration: " . $firstName . " " . $lastName;
$body = "New Registration:\n" . $firstName . " -" . $nickname . "- " . $lastName . "\n" . $street . "\n" . $city . ", " . $state . " " . $zip . "\n" . $country . "\n" . $phone . "\n\nCompany: " . $company . "\nemail: " . $email . "\n" . $gender . "\nAge: " . $age . "\nTeam Name: " . $teamName . "\n" . $food . "\n\n" . $emergencyName . "\n" . $emergencyPhone . "\nYears as a Messenger: " . $years . "\nPrevious Titles: " . $prevTitles . "\nEvents: " . $eventsString . "\nHousing: " . $house . "\n" . $styleString . "\nShirt size: " . $shirt . "\nHub: " . $hub . "\n" . $payment . "\n" . $special ;
$from = "registration@cmwc03.com";
mail($to, $subject, $body, "From: [email]registration@cmwc03.com[/email]\nX-Mailer: PHP Registration Script\n");
}
else
{
echo "Row count returned 0. Variables not sent to CGI script.";
}
?>