Jump to content

long and complicated form that just reloads itself and does not do what it shoul


Recommended Posts

Why is it reloading and not entering the data like it should?

<?php

session_name ('YourVisitID');
session_start(); // Start the session.

// If no session value is present, redirect the user.
if (!isset($_SESSION['user_id'])) {

// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
	$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '../index.php'; // Add the page.
header("Location: $url");
exit(); // Quit the script.
}

// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['event_id'])) && (is_numeric($_GET['event_id'])) ) { // Accessed through view_users.php
$event_id = $_GET['event_id'];
} elseif ( (isset($_POST['event_id'])) && (is_numeric($_POST['event_id'])) ) { // Form has been submitted.
$event_id = $_POST['event_id'];
} else { // No valid ID, kill the script.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
exit();
}

$page_title = 'Attendance of Psi Beta';
require_once ('../includes/mysql_connect.php'); // Connect to the db.





// Check if the form has been submitted.
if (isset($_POST['submitted'])) {



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


foreach($_POST as $value){		
		if ( empty($value) ){
			$msg = 'Please fill out all required fields.';				
			return $msg;
		}
	}


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

	// Register the user in the database.

	// Check for attendance.
	$query5 = "SELECT eid FROM attendance WHERE eid='$event_id'";
	$result5 = mysql_query($query5);
	if (mysql_num_rows($result5) == 1) {

		// Make the query.
foreach($attend as $key => $value2){
  mysql_query("UPDATE attendance SET attend_status='$value2' WHERE mid=$user_id AND eid=$event_id") or die(mysql_error());
}




	$result = @mysql_query ($query); // Run the query.
		if ($result) { // If it ran OK.

			// Send an email, if desired.

			// Redirect the user to the view_users.php page.
			// Start defining the URL.
			$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

			// Check for a trailing slash.
			if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
				$url = substr ($url, 0, -1); // Chop off the slash.
			}

			// Add the page.
			$url .= '/attendance.php';

			header("Location: $url");
			exit();

		} else { // If it did not run OK.
			$errors[] = 'Attendnace for this meeting could not be entered.'; // Public message.
			$errors[] = mysql_error() . '<br /><br />Query: ' . $query5; // Debugging message.
		}

	} else { // Email address is already taken.
		$errors[] = 'Attendance has already been taken for this event.';
	}

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



} else { // Form has not been submitted.

$errors = NULL;

} // End of the main Submit conditional.


// Page header.
echo '<h1 id="mainhead">Attendance</h1>';

$query4 ="SELECT * FROM events WHERE event_id=\"$event_id\"";
$result4 = @mysql_query ($query4); // Run the query.
$row4 = mysql_fetch_array ($result4);

?>
<form action="event_attendance_admin.php?event_id=<?php echo''.$row4['event_id'] .'' ; ?>" method="post">
<?

// Make the query.
$query3 = "SELECT brothers.user_id, CONCAT(brothers.last_name, \", \",  brothers.first_name) AS BrotherName, brothers.status, attendance.attend_status 
FROM brothers
JOIN events
RIGHT JOIN attendance ON (events.event_id = attendance.eid AND brothers.user_id = attendance.mid )
WHERE
events.event_id = \"$event_id\"
AND brothers.status = 'Undergraduate'
GROUP BY brothers.user_id
ORDER BY brothers.last_name";

$result3 = mysql_query ($query3); // Run the query.




// Table header.
echo '<h1 align="center">' . $row4['name'] .', ' . $row4['date'] .'</h1> <table align="center" cellspacing="0" cellpadding="5">
<tr>
<td align="left"><b>Name</b></td>
<td align="left"><b>Current Attendance</b></td>
    <td align="left"><b>Update Attendance</b></td>
</tr>
';

// Fetch and print all the records.
$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result3, MYSQL_ASSOC)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
echo '<tr bgcolor="' . $bg . '">
	<td align="left">' . $row['BrotherName'] . '</td>
	<td align="left">' . $row['attend_status'] . '</td>';

	if ($row['attend_status']  == Present ) {
 	  echo '<td align="left">Present<input type ="radio" name="attend['.$row['user_id'].']" value="Present" checked="checked" />';
          } else {
      echo '<td align="left">Present<input type ="radio" name="attend['.$row['user_id'].']" value="Present" />';
}
	if ($row['attend_status']  == Excused ) {
 	  echo 'Excused<input type ="radio" name="attend['.$row['user_id'].']" value="Excused" checked="checked" />';
          } else {
      echo 'Excused<input type ="radio" name="attend['.$row['user_id'].']" value="Excused" />';
}	

	if ($row['attend_status']  == Unexcused ) {
 	  echo 'Unexcused<input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" checked="checked" />';
          } else {
      echo 'Unexcused<input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" />';
}		

echo '</tr>';
}





echo '</table><p><input type="submit" name="submit" value="Update Attendance" /></p>
<input type="hidden" name="submitted" value="TRUE" /></form>';




?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.