Hi all,
I have trouble in updating my data using update query in which i need to update the a particular student id.Currently in my database table, I have the attendance table below and i need to update it using php update statement.
ID Date
143 1/1/10
143 2/1/10
143 3/1/10
157 1/1/10
157 2/1/10
Since I have no problem extracting data of the particular student id, you can ignore the select statement and I would only show you part of the php code that I need help with the update query part .
Part of my first page of php code:
<?php
include 'dbconfig.inc.php';
$studentid = $_GET['ID'];
$class = $_GET['class'];
$sql = "SELECT ........";
$result = mysqli_query($link,$sql)or die(mysqli_error($link));
$entries = mysqli_num_rows($result);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
Attendance
</title>
<link rel="stylesheet" type="text/css" href="default.css">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div id="article">
<script type="text/javascript" src="datetimepicker.js"></script>
<form method="post" action="doupdate.php" name="form1">
<table border ="1" cellspacing="3" cellpadding="3">
<tr>
<td colspan="2"><b>Date of Attendance> </b></td>
</tr>
<?php
while($row = mysqli_fetch_assoc($result)){
?>
<input type="hidden" name="ID[]" value="<?php echo $row['ID'];?>" />
<tr>
<td><label for="date[]">Date and Time:</label></td>
<td><input type="text" id="date[]" name="date[]" value="<?php echo $row['Date'];?>"/>
<a href="javascript:NewCssCal('date[]','yyyymmdd','dropdown',true)">
<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
</tr>
<?php
}
?>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
Code for doupdate.php page:
<?php
include 'dbconfig.inc.php';
if(isset($_POST['submit'])){
$date = $_POST['date'];
$studentid = $_POST['ID'];
for($i=0;$i<$entries;$i++){
$query ="UPDATE attendance SET Date ='".$date[$i]."' WHERE ID = '".$studentid[$i]."'";
$result = mysqli_query($link,$query) or die(mysqli_error($link));
}
}
?>
In addition to that, i also need help with the javascript calender in which if i click the second and other rows of the calendar, only the value of first date of the textbox change but not the corresponding texbox that is align with the calender.I would appreciate it if someone can help me identify where I have gone wrong in my coding.
Thanks in advanced.