www.webdeveloper.com
Results 1 to 6 of 6

Thread: Attendance system in php

  1. #1
    Join Date
    May 2014
    Posts
    3

    Attendance system in php

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


    PHP Code:
    <?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>

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

    PHP Code:
    <?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);
                }           
    ?>
    I dont know whats the error. on line

    PHP Code:
    $query "INSERT INTO `attendance`(`rollno`,`att`) VALUES ('".$rollno[$key]."','".$at."') "

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    731
    Do you have an error message?

  3. #3
    Join Date
    May 2014
    Posts
    3
    Quote Originally Posted by jitusorout View Post
    I want to take students attendance.
    i had made a page attendance.php
    This is coding part


    PHP Code:
    <?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>

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

    PHP Code:
    <?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);
                }           
    ?>
    I dont know whats the error. on line



    PHP Code:
    $query "INSERT INTO `attendance`(`rollno`,`att`) VALUES ('".$rollno[$key]."','".$at."') "


    Error is

    Undefined offset: 15 in D:\wamp\www\ddddd\attendinsert.php on above line

    Undefined offset: 16 in D:\wamp\www\ddddd\attendinsert.php on line and so on until last result.

  4. #4
    Join Date
    May 2014
    Posts
    75
    $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 $att, yet searching in $rollno.

    Without looking too closely that's my first 20 second look thought.

  5. #5
    Join Date
    May 2014
    Posts
    3
    Take a look with time.

    I don't know how to do that .

    Please guide me

  6. #6
    Join Date
    May 2014
    Posts
    915
    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 giant red warning boxes in the manual 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.

    Code:
    <td align="center"><?php echo '<input type="hidden" name="att[]" value="0"/>';?><?php echo '<input type="checkbox" checked="checked"  name="att[]" value="1"  />'; ?></td>
    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:
    Code:
    <form action="attendinsert.php" method="post"> 
    	<table id="attendance"> 
    		<thead>
    			<tr> 
    				<th scope="col">ID</th> 
    				<th scope="col">Student Name</th> 
    				<th scope="col">Student Roll.No</th> 
    				<th scope="col">Attendance</th> 
    			</tr>
    		</thead><tbody>
    <?php 
    
    /* assumes $db is a connected PDO object */
    
    $statement = $db->query('
    	SELECT id, name, rollno FROM registered_members
    ');
    
    while ($row = $statement->fetch) echo '
    			<tr>
    				<th scope="row">', $row['id'], '</th>
    				<td>', $row['name'], '</td>
    				<td>', $row['rollno'], '</td>
    				<td align="center">
    					<input 
    						type="checkbox"
    						name="att[', $row['rollno'], ']"
    						value="1"
    						checked="checked"
    					/>
    				</td> 
    			</tr>';
    			
    ?>
    		</tbody>
    	</table>
    	<div>
    		<input type="submit" class="submit" value="submit" />
    	</div>
    </form>
    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.
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles