Click here to Skip to main content
15,920,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm new to php. i want to create a attendance page for tutor.

HTML
<form name="form" method="post" action"admin_attendance_edit.php> 

    <table>
    <thead>
    <tr>
    <th>No.</th>
    <th>Name</th>
    <th>Status</th>
    </tr>
    </thead>
    <tbody>
					
    <?php
					
    $count=1;
	$sel_query="Select * from attendance ORDER BY attendance_id desc;";
	$result = mysqli_query($db,$sel_query) or trigger_error("Error". 
    mysqli_error($db));
															
					
	while($row = mysqli_fetch_assoc($result)) {?>
	<tr>
    <td align="center"><?php echo $count; ?></td>
	<td align="center"><?php echo $row["student_name"]; ?></td>
	<td align="center">

    <input type="hidden" name="user_id[]" value="<?php echo $row["user_id"];?>" 
    />
    <input type="hidden" name="name[]" value="<?php echo $row["student_name"]; ? 
    >" />
	<input  name="attendance[]" type="radio" value="present" />Present
	<input  name="attendance[]" type="radio" value="late"/>Late
	<input  name="attendance[]" type="radio" value="absent"/>Absent</td>									
						
	</tr>												
						
    <?php $count++; } ?>
    </tbody>
    </table>
       			
    <p><input name="submit" type="submit" value="Update" /></p> 
		
    </form>  


PHP
<?php
	
	
	if(isset($_POST['submit']))
	{	
			
    foreach ($attendance as $name=> $attendance_status)
		{
		
		$trn_date = date('Y-m-d');	
		$user_id = $_POST['user_id'][$name];
		$student_name =	$_POST['name'][$name];
		
		$update="update attendance set user_id='".$user_id."', student_name='".$student_name."' , 
										attendance_status='".$attendance_status."', date='".$trn_date."' 
										
										";
	mysqli_query($db, $update) or trigger_error( "Error!". mysqli_error($db));
	header('location: admin_attendance.php');
	
	}


What I have tried:

Can anyone tell me anything wrong in my code.thanks.
Posted
Updated 14-Nov-18 19:21pm

1 solution

Not clear what you trying to accomplish here, the code has major flaws
1. It update all the record in the table
2. SQL Injection vulnerability


--SQL Injection prevention example
The Hitchhiker's Guide to SQL Injection prevention - Treating PHP Delusions[^]

--PHP MySQL update example
PHP Update Data in MySQL[^]
 
Share this answer
 
Comments
Member 13965471 15-Nov-18 1:50am    
am i using 'foreach' in correct way?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900