Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Am sure of two things, It worked for my professor but not for me, and am sure that the error comes from the echo part in this code below not from another place.

To let you try things yourself, I provided my work in a link http://agencedevoyages.tk/[^]
enter the address: abc@gmail.com
and the password is: 2
or sign in with a new user of your choice.

Error code:
PHP
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Accueil</title>
</head>
<body>
<?php
if(isset($_SESSION['email']) AND isset($_SESSION['password']))
{
echo "<b>Bienvenue ".$_SESSION['prenom']." ".$_SESSION['nom']." !";
echo "<div align='right'><a align='right' href='deconnect.php'><button type='button'>Se déconnecter</button></a></div>";
?>
<table border="1" align="center">
<caption><b><h1>La liste des étudiants</h1></caption>
<tr><td align="center"><b>Photo</td>
<td align="center"><b>Matricule</td>
<td align="center"><b>Nom</td>
<td align="center"><b>Prénom</td>
<td align="center"><b>Adress</td>
<td align="center"><b>Birthday</td>
<td align="center"><b>E-mail</td>
<td align="center" colspan="2"><b>Option</td>
<td align="center"><b>Multiple Deletion</td>
<td align="center"><b>Upload</td></tr>
<?php
include 'connect.php';
$sql = "SELECT * FROM etudiant";
$res = mysqli_query($connect, $sql);
if (mysqli_num_rows($res)>0){
while($row = mysqli_fetch_assoc($res))
{
echo "<tr><td>";
?>
<?php
if(empty($row['photo']))
{
?>
<img src='photos/image.jpg' width="100" height="100">
<?php
}
else
{
?>
<img src='photos/<?php echo $row['photo'] ?>' width="100" height="100">
<?php
}
echo "</td>";
echo "<td align='center'>".$row['matricule']."</td>";
echo "<td align='center'>".$row['nom']."</td>";
echo "<td align='center'>".$row['prenom']."</td>";
echo "<td align='center'>".$row['adresse']."</td>";
echo "<td align='center'>".$row['date_naissance']."</td>";
echo "<td align='center'>".$row['email']."</td>";
if($_SESSION['email']==$row['email'] OR $_SESSION['email']=='abc@gmail.com')
{
echo "<td><a href='modif.php?id=".$row['id']."'><button type='button'>Edit</button></a></td>";
echo "<td><a href='supp.php?id=".$row['id']."'><button type='button'>Delete</button></a></td>";

// error part 
echo "<form method='post' action='supp3.php'><td align='center'><input type='checkbox' name='sup[]' value='".$row['id']."'></td></form>";
echo "<form method='post' action='upload.php' enctype='multipart/form-data'><td align='center'><input type='file' name='fichier'><input type='submit' value='Confirm'></td><input type='hidden' name='id' value='".$row['id']."'></td></tr>";
}
}
echo "<tr><td colspan='9'></td><td colspan='1' align='center'><button>Multiple Deletion</button></td></tr></form>";
}
//end of error part

else
{
echo "<tr><td colspan ='10' align='center'>No users.</td></tr>";
$sql = "TRUNCATE etudiant";
$res = mysqli_query($connect, $sql);
}
?>
</table>
<p align="center"><a href="ajout.php"><button>Add a user</button></a></p>
<?php
}
else
{
echo "<div align='center'><b><h1>Not allowed.";
echo "<br><a href='index.php'><button type='button'>Back</button></a></div>";
}
?>
</body>
</html>


What I have tried:

- Closing < / form > in the Multiple Deletion echo condition, and not in the upload one makes me able to delete multiple users but unable to upload pictures.
- Same happens when i keep it for both.
- Removing < / form > from the Multiple deletion echo and keeping it in the Uplaod echo condition makes me unable to delete multiple users but able to change the user's picture (meaning Upload works and Deletion doesn't).
- Removing the closed < / form > from both coniditions makes MD work and not Upload.

Still trying to figure out a way to get them both working at the same time.
Posted
Updated 8-Jun-23 21:38pm
v8

1 solution

What you've shown certainly didn't work for your professor:
  • You cannot nest <form> elements. Your "upload" form is never closed, so each subsequent form is nested within the forms from the previous rows.
  • A <form> element cannot appear directly within a <tr> element. Only <td> and <th> elements are allowed within a <tr> element.

For a start, you will need to move the <form> elements inside the <td> elements, and make sure they're closed in the correct order.
HTML
<td><form> ... </form></td>
However, it's not clear what your checkbox is meant to do. If you were wanting to submit the ID from multiple rows, this will not work - each form will only contain the checkbox for its own row.
 
Share this answer
 
Comments
Jakezer 9-Dec-20 13:50pm    
I moved the form inside td but still doesn't work :/

And, before adding the upload row (which works sometimes) the multiple used to work, now after adding the upload conditions they work but not at the same time.

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