/    Sign up×
Community /Pin to ProfileBookmark

Attendance system in php

I want to take students attendance.
i had made a page attendance.php
This is coding part

[code=php]<?php
$report = mysql_query(“SELECT id, name, rollno FROM registered_members”) or die(mysql_error());
?>
<form action=”attendinsert.php” method=”post”>
<table id = “attendance” width=”567″ border=”1 bold”>
<tr>
<th width=”83″ scope=”col”>ID</th>
<th width=”83″ scope=”col”>Student Name</th>
<th width=”55″ scope=”col”>Student Roll.No</th>
<th width=”51″ scope=”col”>Attendance</th>
</tr>
<?php while(list($id, $name, $rollno) = mysql_fetch_row($report))
{
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $name ?></td>
<td><?php echo $rollno ?></td>
<td align=”center”><?php echo ‘<input type=”hidden” name=”att[]” value=”0″/>’;?><?php echo ‘<input type=”checkbox” checked=”checked” name=”att[]” value=”1″ />’; ?></td>
<input type=”hidden” name=”rollno[]” value=”<?php echo $rollno; ?>” />
</tr>
<?php
}
echo ‘</table>’;
?>
<input type=”submit” name =”submit2″ id=”submit2″ value =”submit”></input>
</form>
[/code]

///////////////////////////////////////////////////////
And the second page is attendinsert.php
by which i want to save data in attendance table

[code=php]<?php
$att = $_POST[‘att’];
$rollno = $_POST[‘rollno’];
foreach($att as $key => $attendance) {
$at = $attendance ? ‘1’ : ‘0’;
$query = “INSERT INTO `attendance`(`rollno`,`att`) VALUES (‘”.$rollno[$key].”‘,'”.$at.”‘) “;
$result = mysql_query($query);
}
?>
[/code]

I dont know whats the error. on line

[code=php]$query = “INSERT INTO `attendance`(`rollno`,`att`) VALUES (‘”.$rollno[$key].”‘,'”.$at.”‘) “;
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMay 28.2014 — Do you have an error message?
Copy linkTweet thisAlerts:
@jitusoroutauthorMay 31.2014 — I want to take students attendance.

i had made a page attendance.php

This is coding part


[code=php]<?php
$report = mysql_query("SELECT id, name, rollno FROM registered_members") or die(mysql_error());
?>
<form action="attendinsert.php" method="post">
<table id = "attendance" width="567" border="1 bold">
<tr>
<th width="83" scope="col">ID</th>
<th width="83" scope="col">Student Name</th>
<th width="55" scope="col">Student Roll.No</th>
<th width="51" scope="col">Attendance</th>
</tr>
<?php while(list($id, $name, $rollno) = mysql_fetch_row($report))
{
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $name ?></td>
<td><?php echo $rollno ?></td>
<td align="center"><?php echo '<input type="hidden" name="att[]" value="0"/>';?><?php echo '<input type="checkbox" checked="checked" name="att[]" value="1" />'; ?></td>
<input type="hidden" name="rollno[]" value="<?php echo $rollno; ?>" />
</tr>
<?php
}
echo '</table>';
?>
<input type="submit" name ="submit2" id="submit2" value ="submit"></input>
</form>
[/code]



///////////////////////////////////////////////////////

And the second page is attendinsert.php

by which i want to save data in attendance table

[code=php]<?php
$att = $_POST['att'];
$rollno = $_POST['rollno'];
foreach($att as $key => $attendance) {
$at = $attendance ? '1' : '0';
$query = "INSERT INTO attendance(rollno,att) VALUES ('".$rollno[$key]."','".$at."') ";
$result = mysql_query($query);
}

?>
[/code]
I dont know whats the error. on line



[code=php]$query = "INSERT INTO attendance(rollno,att) VALUES ('".$rollno[$key]."','".$at."') ";
[/code]
[/QUOTE]




Error is

Undefined offset: 15 in D:wampwwwdddddattendinsert.php on above line

Undefined offset: 16 in D:wampwwwdddddattendinsert.php on line and so on until last result.
Copy linkTweet thisAlerts:
@GravyJun 01.2014 — $rollno[$key]

What the error is saying as that $rollno has nothing at position 15.

$rollno[15] <=== is undefined, it isn't set.


foreach($att as $key => $attendance)

You're iterating over [B]$att[/B], yet searching in [B]$rollno[/B].

Without looking too closely that's my first 20 second look thought.
Copy linkTweet thisAlerts:
@jitusoroutauthorJun 01.2014 — Take a look with time.

I don't know how to do that .

Please guide me
Copy linkTweet thisAlerts:
@deathshadowJun 01.2014 — Well, first, need to read you the riot act -- this is 2014, you shouldn't be writing new programs using mysql_ functions, since we've been told for EIGHT YEARS to stop doing that, and for almost three years now there have been [url=http://us2.php.net/function.mysql-connect][b]giant red warning boxes in the manual[/b][/url] telling you not to do that!

Second, blindly dumping $_POST values into a query string is BEGGING to get hacked.

Now that's the initial bad news, the good news is if you switch to mysqli or PDO like a good little doobie, "prepared queries" will mean you CAN dump $_POST into a bind or execute array; and the prepare/execute model is designed for EXACTLY the type of thing you are doing iterating your values.

Now, that said... Your form has problems. on top of the fictional border attribute value, attributes like border, align, width that have no business in any HTML written after 1997, and missing/incomplete closures -- there's the real root of your problem, -- name attributes that don't line up.

&lt;td align="center"&gt;&lt;?php echo '&lt;input type="hidden" name="att[]" value="0"/&gt;';?&gt;&lt;?php echo '&lt;input type="checkbox" checked="checked" name="att[]" value="1" /&gt;'; ?&gt;&lt;/td&gt;

On top of the mutliple echo for nothing, you realize that the first att[] will be att[0], the second one att[1], on the next loop it will be 2 and 3, so they will NOT correspond to "rollno" 1:1 when you try to loop through them.

I'd suggest putting $rollno as the index inside ATT... though, is rollno really appropriate? Wouldn't the ID make more sense? Well, maybe not... not sure I follow what it is you are even trying to here as it makes no real sense.

Guessing WILDLY, let's start by fixing the markup:
&lt;form action="attendinsert.php" method="post"&gt;
&lt;table id="attendance"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;ID&lt;/th&gt;
&lt;th scope="col"&gt;Student Name&lt;/th&gt;
&lt;th scope="col"&gt;Student Roll.No&lt;/th&gt;
&lt;th scope="col"&gt;Attendance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;?php

/* assumes $db is a connected PDO object */

$statement = $db-&gt;query('
SELECT id, name, rollno FROM registered_members
');

while ($row = $statement-&gt;fetch) echo '
&lt;tr&gt;
&lt;th scope="row"&gt;', $row['id'], '&lt;/th&gt;
&lt;td&gt;', $row['name'], '&lt;/td&gt;
&lt;td&gt;', $row['rollno'], '&lt;/td&gt;
&lt;td align="center"&gt;
&lt;input
type="checkbox"
name="att[', $row['rollno'], ']"
value="1"
checked="checked"
/&gt;
&lt;/td&gt;
&lt;/tr&gt;';

?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div&gt;
&lt;input type="submit" class="submit" value="submit" /&gt;
&lt;/div&gt;
&lt;/form&gt;


Then, let's fix the handler... no, wait... what the ? Ok, I'm just not getting what it is you are even trying to do here.
×

Success!

Help @jitusorout spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...