Example #1
0
        ?>
						<form action="" method="post">
							<input type="hidden" name="Event_ID" value="<?php 
        echo $this_event['id'];
        ?>
"/>
							<input type="hidden" name="User_ID" value="<?php 
        echo $_SESSION['user_id'];
        ?>
"/>
							<input type="hidden" name="csrf" value="<?php 
        echo $_SESSION['csrf'];
        ?>
">
							<?php 
        if (checkIfUserAttends($this_event['id'], $_SESSION['user_id'])) {
            ?>
								<input class="leave-event-button" name="LeaveEvent" type="submit" value="Leave Event">
							<?php 
        } else {
            ?>
								<input class="join-event-button" name="JoinEvent" type="submit" value="Join Event">
							<?php 
        }
        ?>
						</form>
						<span class="event-creator">Creator: <?php 
        echo "<a href='profile.php?id=" . $this_event["user_id"] . "'>" . getUserByID($this_event['user_id'])['user_name'] . "</a>";
        ?>
</span>
						<span class="event-type"><?php 
<?php

if (isset($_POST['LeaveEvent']) && $_SESSION['csrf'] == $_POST['csrf']) {
    if (checkIfUserAttends($_POST['Event_ID'], $_POST['User_ID'])) {
        leaveEvent($_POST['Event_ID'], $_POST['User_ID']);
    }
}
if (isset($_POST['JoinEvent']) && $_SESSION['csrf'] == $_POST['csrf']) {
    if (!checkIfUserAttends($_POST['Event_ID'], $_POST['User_ID'])) {
        insertAttend($_POST['Event_ID'], $_POST['User_ID']);
    }
}