New member - Need help with RSVP.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jeremy1026
Forum Newbie
Posts: 2
Joined: Tue Sep 01, 2009 8:01 pm

New member - Need help with RSVP.

Post by Jeremy1026 »

Hello, I am writing a dynamic website for a local car club I participate in. I am trying to set up an RSVP system for gatherings. What I am doing is, when a new event is posted it creates a row in a MySQL database with information about the event, as well as three blank fields, Yes, No, and Maybe. When a user RSVPs to the even their name is added to the field. When displaying the RSVP status I separate the people who responded by " " and display them in a list. This all works great. But, if a user decides they want to change their RSVP status everything falls apart. I want to remove the users name from the field and add it to the one they are now RSVPing for. Here is the code I am currently using, which does NOT work. If anyone could help me with this one I'd greatly appreciate it. Either help with the code or by providing another idea on how to make it work.

Code: Select all

 
<? php
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query='SELECT * FROM `events`';
 
$result=mysql_query($query);
 
$num=mysql_numrows($result);
 
$yes = "Yes";
$no = "No";
$maybe = "Maybe";
$blank = "";
$i = 0;
$j = 0;
 
$a = strcmp($attend,$yes);
$b = strcmp($attend,$no);
$c = strcmp($attend,$maybe);
 
echo "Submitting RSVP...<br>";
 
$counting = 0;
while ($counting < $num) {
    
    if (strcmp($event, mysql_result($result,$counting,"eventid"))) {
        if ($a == 0) {
            $newCount = $counting - 1;
            $ayes = mysql_result($result,$newCount,"yes");
            $ayes .= " ".$_SESSION['user'];
 
            $newResult = mysql_query('UPDATE `onezerv2_c3m`.`events` SET yes = \''.$ayes.'\' WHERE eventid = \''.$event.'\' ');
            $freshmaybe = explode(" ", mysql_result($result,$newCount,"maybe"));
            $k = count($freshmaybe);
            
        
            while ($i < $k) {
                echo '<br>i = '.$i;
 
                $newMaybe = "";
                $theUser = "".$_SESSION['user'];
                $comp2 = strcmp($freshmaybe[$i], $theUser);
                echo "<br>comp ".$comp2;
                
                if($comp2 == 0) {
                    echo '<br>i = '.$i;
                    $change = $i;
                    echo '<br>original = "'.$freshmaybe[$change];
                    $freshmaybe[$i] = "";
                    echo '"<br>fresh = "'.$freshmaybe[$i];
                    echo '"<br>changed = "'.$freshmaybe[$change];
                    $space = " ";
                    echo '"<br>already rsvp\'d';
                    while ($j < $k) {
                        echo "<br>while loop i = ".$j;
                        echo '" and change = "'.$change;
                        if ((strcmp($freshmaybe[$j], $blank) != 0) && ($j != $change)) {
                            $newMaybe .= $freshmaybe[$j];
                            if ($j < $change - 1) {
                                $newMaybe .= $space;
                            }
                            echo "'<br>newMaybe = '".$newMaybe;
                            echo "'<br>";
                        }
                        else {
                            $newMaybe .= $freshmaybe[$j];
                            echo "<br>newMaybe = '".$newMaybe;
                            echo "'<br>";
                        }
                    $j++;    
                    }
 
                }
                $i++;
            }
            if (($i == $k) && ($i != 0)) {
                echo "<br>writing";
                $newResult = mysql_query('UPDATE `onezerv2_c3m`.`events` SET maybe = \''.$newMaybe.'\' WHERE eventid = \''.$event.'\' ');        
                die();
            }   
            
            
        die ();
 
        }
 
    }
    $counting++;
    
}
?>
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New member - Need help with RSVP.

Post by califdon »

An outstanding mini-tutorial for this task, McInfo! Congratulations.
Post Reply