the program is basically a table with three btns for each row (Update, profile, delete).
the update and the delete btn is working perfectly, but the profile btn doesn't work the same for all of the table:).
it is supposed to redirect the user to a profile page but it's only doing it for first three rows and fails to redirect after that.
I tried to add a printf statement so I know if the if statement is getting called, and the printf is getting called properly but the redirect line is not working at all after the index 3.
i'll add the related code now :
while($row =mysqli_fetch_assoc($result)){
echo '<tr>' ;
echo '<td>'.'<input type="text" name="id'.$i.'" value="'.$row['emp_id'].'"/> '.'</td>';
echo '<td>'.'<input type="text" name="fname'.$i.'" value="'.$row['emp_fname'].'" />'.'</td>';
echo '<td>'.'<input type="text" name="lname'.$i.'" value="'.$row['emp_lname'].'" />'.'</td>';
echo '<td>'.'<input type="text" name="phone_number'.$i.'" value="'.$row['emp_phonenumber'].'" >'.'</td>';
echo '<td>'.'<input type="text" name="email'.$i.'" value="'.$row['emp_email'].'"/> '.'</td>';
echo '<td>'.'<input type="text" name="salary'.$i.'" value="'.$row['emp_salary'].'"/> '.'</td>';
echo '<td>'.'<input type="text" name="status'.$i.'" value="'.$row['emp_status'].'" />'.'</td>';
echo '<td> <input type="submit" name="update_btn'.$i.'" value="update"/> ';
echo '<td> <input type="submit" name="profile_btn'.$i.'" value="profile"/> ';
if(isset($_GET['profile_btn'.$i])){
// the profile btn has been pressed..
header("Location: profile.php") ;
printf("Location : " . $i) ;
}
if(isset($_GET['update_btn'.$i])){
if(isset($_GET['check'.$i])){
$id = $_GET['id'.$i];
$fname = $_GET['fname'.$i] ;
$lname = $_GET['lname'.$i];
$phone_number = $_GET['phone_number'.$i];
$email = $_GET['email'.$i];
$salary =$_GET['salary'.$i] ;
$status =$_GET['status'.$i];
$updateStatus = "update employees set emp_fname ='$fname' , emp_lname='$lname' ,emp_phonenumber='$phone_number', emp_email='$email', emp_salary='$salary', emp_status='$status' WHERE emp_id = '$id' " ;
$qry = mysqli_query($con,$updateStatus);
if(!$qry){
echo 'failed to update...';
}else{
header("Location: employee.php");
}
}else{
echo'please activate the update modification options using the tick' ;
}
}
echo '</td>';
echo '<td>' ;
echo ' <input type="submit" name="delete'.$i.'" value="delete"/> ';
if($_GET['delete'.$i]){
if($_GET['check'.$i]){
$id = $_GET['id'.$i];
$delete = "delete from employees where emp_id = '$id'";
$query = mysqli_query($con,$delete);
if(!$query){
echo'delete faile';
}else{
header("Location: employee.php");
}
}
}
echo '</td>';
echo '<td>' ;
echo '<input type="Checkbox" name="check'.$i.'" />' ;
echo '</td>' ;
echo'</tr>';
$i++;
}
the problem is only related to the profile btn and nothing else.
the whole file is here ::
https://drive.google.com/file/d/13gnoC5jhYfmi8vaJsJJs9KBvb61wQpoj/view?usp=sharing