Jump to content

RSVP form


dimendoll

Recommended Posts

Hi, I am writing an RSVP form and I am having trouble getting a recorded response form the dropdown boxes. it looks as though the inputted values are not being read at all. I am getting errors:

 

Error!

 

The following error(s) occured:

- Please let us know if you are joining us on our happy day.

- Please confirm which events you are attending.

 

Please try again.

 

Here is my code:

<?php # rsvp2.php

//March 2010

session_start();

 

//check if the form has been submitted:

if (isset($_POST['submitted'])) {

$errors = array(); // Initialize and error array.

 

require_once ('../mysqli_connect.php');

//connect to the db.

 

//check for number of guests:

if (empty($_POST['attending'])) {

$errors[] = 'Please let us know if you are joining us on our happy day.';

} else {

$a =mysqli_real_escape_string($dbc,trim($_POST['attending']));

}

 

//Check for a first name:

if (empty($_POST['guest1'])) {

$errors[] = 'You forgot to enter your name.';

}else{

$g1=mysqli_real_escape_string($dbc,trim($_POST['guest1']));

}

 

//Guest 2

if (!empty($_POST['guest2'])) {

$g2 =mysqli_real_escape_string($dbc,trim($_POST['guest2']));

}

 

//Guest 3

if (!empty($_POST['guest3'])) {

$g3 =mysqli_real_escape_string($dbc,trim($_POST['guest3']));

}

 

//Guest 4

if (!empty($_POST['guest4'])) {

$g4 =mysqli_real_escape_string($dbc,trim($_POST['guest4']));

}

 

//check for type of party attendance:

if (empty($_POST['event'])) {

$errors[] = 'Please confirm which events you are attending.';

} else {

$event =mysqli_real_escape_string($dbc,trim($_POST['event']));

}

 

if(empty($errors)) { //If everything's OK.

 

//Register the user in the database...

 

 

//Make the query:

$q = "INSERT INTO rsvp ( attending, guest1, guest2, guest3, guest4, event) VALUES ('$a', '$g1', '$g2', '$g3', '$g4', '$event' )";

$r = mysqli_query ($dbc, $q); // Run the query.

if ($r) {// If it ran OK.

 

//Print a message:

echo '<h1>Thank you!</h1>

<p> we appreciate your response. </p><p><br /></p>';

 

}else {// If it did not run OK.

 

// Public message:

echo '<h1>System Error</h1>

<p class="error"> You could not be registered due to a system error. We apologise for any inconvenience.</p>';

 

//Debugging message:

echo '<p>' . mysqli_error($dbc). '<br /><br /> query: ' . $q. '</p>';

}

// End of if ($r) IF.

 

mysqli_close($dbc);

 

// Close the database connection.

//Include the footer and quit the script:

 

exit();

 

} else { //Report the Errors.

 

echo '<h1>Error!</h1> <p class="error"> The following error(s) occured:<br />';

foreach ($errors as $msg) {// Print each error.

echo " - $msg<br />\n";

}

echo '</p><p>Please try again. </p><p><br /></p>';

} // End of if (empty($errors)) IF.

 

mysqli_close($dbc);// Close the database connection.

}

session_write_close();

//End of the main Submit conditional.

 

?>

<h1> RSVP</h1>

<form action="rsvp2.php" method="post">

<p>Please indicate how many people are attending on your invitiation, or if you can't make it select "None" and leave your name.

  <?php

  $attendees = array (1=> 'Select one', 'none', 'one', 'two', 'three', 'four');

 

echo '<select name="attendees">';

 

foreach ($attendees as $key => $attending) {

 

echo "<option value= \"$key\" >$attending</option>\n";

 

}

 

echo '</select>';

?></p>

  <p>Name 1: <input type="text" name="guest1" size="60" maxlength="80" value="<?php if (isset($_POST['guest1'])) echo $_POST['guest1'];?>" /></p>

   

   

    <p>Partner or Guest name 2: <input type="text" name="guest2" size="60" maxlength="80" value="<?php if (isset($_POST['guest2'])) echo $_POST['guest2']; ?>" /></p>

   

    <p> *Please indicate childrens' names if you have recieved a family invitation:</p>

    <p>Partner or Guest name 3: <input type="text" name="guest3" size="60" maxlength="80" value="<?php if (isset($_POST['guest3'])) echo $_POST['guest3']; ?>" /></p>

   

    <p>Partner or Guest name 4: <input type="text" name="guest4" size="60" maxlength="80" value="<?php if (isset($_POST['guest4'])) echo $_POST['guest4']; ?>" /> </p>

 

  <p> Please let us know what part of our day you will be sharing:</p>

    <p>

<?php

$party = array (1=> 'Select one', 'None', 'All', 'Ceremony only', 'Ceremony and Dinner', 'Ceremony and Dance', 'Dinner only', 'Dinner and Dance', 'Dance only');

 

echo '<select name="party">';

 

foreach ($party as $key => $event) {

 

echo "<option name =\"$key\">$event</option>\n";

 

}

if (isset($_POST['event'])) echo $_POST['event'];

   

echo '</select>';

?>

</p> 

   

    <p><input type="submit" name="submit" value="RSVP" /> </p>

   

    <input type="hidden" name="submitted" value="true" />

    </form>

Can you help me with this puzzle? I am trying to get it to write to a  database.

Link to comment
https://forums.phpfreaks.com/topic/197416-rsvp-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.