Forum Moderators: coopster

Message Too Old, No Replies

Could not Update Using PHP

         

appletea

1:31 pm on Jan 15, 2011 (gmt 0)

10+ Year Member



Hi,

I have this attendance table in which the ID represent the students enrolled in the school and the DateTime using datetimestamp in the database represent the date and time they have scanned their card to attend classes.Currently I am facing two issues.

1)I could not update multiple rows of DateTime of a particular student.
2)The javascript calendar seem do not be aligned with the corresponding datetime textbox. You can view the image here:[flickr.com ]


Here are part of my codes and database table:

Database Table:
ID Card DateTime
147 E900 28/12/2010 14:19
147 E900 06/12/2010 12:20
... ... .......
... ... .....
157 E901 18/12/2010 13:10

update.php form:

<?php
include 'dbconfig.inc.php';
$a = $_GET['idStudent'];
$code = $_GET['course_code'];


$sql = "SELECT..................idStudent='$a' AND course_code= '$code' ORDER BY course_code ,DateTime";
$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>
</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">
<h3>
</h3>
<script type="text/javascript" src="datetimepicker.js"></script>
<form name="form1" method="post" action="doupdate.php">
<table border ="1" cellspacing="3" cellpadding="3">

<tr>
<td colspan="4"><b>Date of Attendance> </b></td>
</tr>
<?php
for ($i=0;$i<$entries;$i++){
while($row = mysqli_fetch_assoc($result)){
?>
<tr>
<td><input type ='hidden' name="ID" value="<?php echo $row['ID']; >" /> </td>
</tr>

<tr>
<td><label for="date[]">Date and Time:</label></td>
<td><input type="text" id="date[]" name="date[]" value="<?php echo $row['DateTime'];?>"/>

<a href="javascript:NewCssCal('date[]','yyyymmdd','dropdown',true)">
<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
<span class="Infostyle1">*</span></td>

</tr>

<?php
}}
?>

<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>


doupdate.php

<?php
include 'dbconfig.inc.php';
//grab the user-entered data
$a = $_POST['ID'];
$submit = $_POST['submit'];
$date = $_POST['date'];

if(isset($_POST['submit'])){
for($i=0;$i<$entries;$i++){

$query ="UPDATE attendance SET DateTime ='".$date[$i]."' WHERE ID = '".$a."'";
$result = mysqli_query($link,$query) or die(mysqli_error($link));
}
}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
</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">
<h1>
Update Attendance
</h1>

<?php
if ($result) {
?>
<p>Attendance has been updated.</p>
<?php
} // end of if
?>
<a href= "home.php">Home</a><br>

</div>
</body>
</html>




Could someone please suggest to me where/what I should edit in my code in such that I could solve the 2 issues that I faced currently. Thanks in advance.

coopster

3:11 pm on Feb 3, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's hard to tell from the code here, but are you certain you are ending up with unique id attributes on each element on your display? Whenever you use a loop construct to build HTML data for display, be certain you are not creating multiple id's on the page with same exact value. You break the DOM this way.