|
Hi Everyone,
Im new here, but i seriously need help. Am trying to create an attendance form that require 3 radio buttons per name.
The data from the table is extracted from the database. Everything works fine, cept when i try to insert or update the database, nothing works.
I've provided the update code too. Hope someone could help me.. its been 3days im hogged onto it...
Thks in advance!
As shown, this is the code for attendance.
<?php
// Make a MySQL Connection
$id="$_SESSION[SESS_MEMBER_ID]";
$username="";
$password="";
$database="";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$my_t=getdate(date("U"));
print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");
function querysql() {
$query = "SELECT studentName, studentClass, studentID FROM students WHERE studentClass ='4.1'";
$result = mysql_query($query) or die(mysql_error());
$query1 = "";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)){
$qname = $row['studentID'];
$query1 .= "<tr><td>";
$query1 .= $row['studentName'];
$query1 .= "</td><td>";
$query1 .= $row['studentID'];
$query1 .= "</td><td>";
$query1 .= $row['studentClass'];
$query1 .= "</td>";
$query1 .= "<td><input type=\"radio\" class=\"attendance\" value=\"Present\" name=\"$qname\">
Present
<input type=\"radio\" class=\"attendance\" value=\"Absent\" name=\"$qname\">
Absent
<input type=\"radio\" class=\"attendance\" value=\"Status\" name=\"$qname\">
Status
</td></tr>";
}
return $query1;
}
// #test is tr info of student followed by radio button of name = studentid
$test = querysql();//call function querysql
?>
<html>
<head>
<title>Student Attendance List</title>
</head>
<body>
<h1>Student Attendance</h1>
<form action="update.php" method="post" >
<table border='1'>
<tr> <th>Name</th> <th>Student ID</th> <th>Student Class</th> <th>Attendance</th>
<?= $test ?>
<td></td> <td></td> <td></td> <td><input type="submit" value="enter"></td></tr>
</table>
</form>
<hr>
Copyrighted DJ Inc
</body>
</html>
This is the update code:
<?php
$studentName = $_POST['studentName'];
$studentID = $_POST['studentID'];
$studentClass = $_POST['studentClass'];
$attendance = $_POST['attendance'];
$userdate = $_POST['my_t'];
$username="";
$password="";
$database="";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "UPDATE students SET studentName = '$studentName', studentClass = '$studentClass', attendance = '$attendance' WHERE studentID = '$qname'";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>
|