i have an rsvp page where the table is populated by guests according to event selected in the drop down list. the rsvp table has 2 columns: guest names and status. status(radio button) is divided into 3: unconfirmed(default status), attending and not attending. user has to choose either one. but i am having trouble saving the status. tia for any help!
php getting the list of names:
<?php
$t = $_GET['t'];
require "connection.php";
$check = $dbh->prepare("SELECT guest_id,guest_name,status FROM guest WHERE event_id = :t ");
$check->bindParam(':t', $t);
$check->execute();
if ($check->rowCount() > 0)
{
$check->setFetchMode(PDO::FETCH_ASSOC);
$Guests = 0;
$Unconfirmed = 0;
$Attending = 0;
$NotAttending = 0;
while ($row = $check->fetch())
{
$id = $row['guest_id'];
$name = $row['guest_name'];
$status = $row['status'];
$status_array = array("Unconfirmed", "Attending", "Not Attending");
//Get counts
$Guests++;
switch ($status) {
case 0:
$Unconfirmed++;
break;
case 1:
$Attending++;
break;
case 2:
$NotAttending++;
break;
}
echo "<tr>";
echo "<td><input type='hidden' name='name[]' value='$name'><span>$name</span></td>";
foreach($status_array as $k => $v):
$checked = ($status == $k ? ' checked="checked"' : '');
echo "<td><input type='radio' name='rsvp[" . $id . "]' value='" . $k . "'" . $checked . " />" . $v . "</td>";
endforeach;
echo "</tr>";
}
echo "<tr><td><label>Total Guests : </label></td><td><input type='text' name='total-guest' value='" . $Guests . "' readonly></td></tr>
<tr><td><label>Unconfirmed : </label></td><td><input type='text' name='unconfirmed' value='" . $Unconfirmed . "' readonly></td></tr>
<tr><td><label>Attending : </label></td><td><input type='text' name='attending' value='" . $Attending . "' readonly></td></tr>
<tr><td><label>Not Attending : </label></td><td><input type='text' name='not-attending' value='" . $NotAttending . "' readonly></td></tr>\r";
}
else
{
echo "<tbody><tr><td>No Guests invited.</td><td></td></tr>";
}
?>
table by default:
saving code is this :
<?php
if(isset($_SESSION['sess_user_id']))
{
if(isset($_POST['save-rsvp']))
{
require "connection.php";
$name = $_POST['name'];
$radio = $_POST['rsvp'];
$session = $_SESSION['sess_user_id'];
$rsvp = $dbh->prepare("UPDATE guest SET status = ? WHERE guser_id = ? AND guest_name = ?");
$rad = implode("','", $radio);
for($i = 0; $i < count($_POST['name']); $i++)
{
if(trim($_POST['name'][$i]) !== '')// validate this form
{
$rsvp->bindParam(1, $rad, PDO::PARAM_INT);
$rsvp->bindParam(2, $session, PDO::PARAM_INT);
$rsvp->bindParam(3, $name[$i], PDO::PARAM_STR);
$rsvp->execute();
}
}
}
}
?>
this was the status's chosen:
but when rsvp is saved :
all is saved as "Attending"
when code changed to this :
<?php
if(isset($_SESSION['sess_user_id']))
{
if(isset($_POST['save-rsvp']))
{
require "connection.php";
$name = $_POST['name'];
$radio = $_POST['rsvp'];
$session = $_SESSION['sess_user_id'];
$rsvp = $dbh->prepare("UPDATE guest SET status = ? WHERE guser_id = ? AND guest_name = ?");
//$rad = implode("','", $radio);
for($i = 0; $i < count($_POST['name']); $i++)
{
if(trim($_POST['name'][$i]) !== '')// validate this form
{
$rsvp->bindParam(1, $radio[$i], PDO::PARAM_INT);
$rsvp->bindParam(2, $session, PDO::PARAM_INT);
$rsvp->bindParam(3, $name[$i], PDO::PARAM_STR);
$rsvp->execute();
}
}
}
}
?>
and when rsvp is saved :
the first name is saved as "Unconfirmed".