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:

2de8bb71beddc6d8c762d6b2505272ea

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:

9569659e4b61de8501ff7c4e929c11df
but when rsvp is saved :
f2fa7b00fe68a28b31649f4d9a705aeb
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 :
f3a790bf7139ed161708adcf8a82323c
the first name is saved as "Unconfirmed".

no one can help me? :( pleaseee

i got the saving to work.

?php
if(isset($_SESSION['sess_user_id']))
{
    if(isset($_POST['save-rsvp']))
    {
        require "connection.php";
        $id = $_POST['guest_id'];
        $session = $_SESSION['sess_user_id'];

        $rsvp = $dbh->prepare("UPDATE guest SET status = ? WHERE guser_id = ? AND guest_id = ?");

        if(is_array($id))
        {
            foreach($id as $value){
                $name  = $_POST['names'][$value];
                $radio = $_POST['rsvp'][$value];

                $rsvp->bindParam(1, $radio, PDO::PARAM_INT);
                $rsvp->bindParam(2, $session, PDO::PARAM_INT);
                $rsvp->bindParam(3, $value, PDO::PARAM_INT);
                $rsvp->execute();
            }
        }
    }
}
?>

and i tweeked 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'];
            $name2 = htmlspecialchars($name, ENT_QUOTES);
            $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='guest_id[]' value='$id'>
            <input type='hidden' name='names[".$id."]' value='$name2'><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>";
    }
?>

notice:

echo "<tr>";
        echo "<td><input type='hidden' name='guest_id[]' value='$id'>
            <input type='hidden' name='names[".$id."]' value='$name2'><span>$name</span></td>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.