Page 1 of 1

Display Data from MySQL Database into HTML Table using PHP

Posted: Sat Jun 27, 2020 7:20 pm
by imane chakri
hey guys, i create a database in phpadmin , it name is "db" and i followed the same code using in this video https://www.youtube.com/watch?v=bHFoobciCTM and nothing !!
this is the message that i received when i run my code :

connect_error) { die("connection failed:". $conn-> connect_error); } $sql = "SELECT id, nom, prenom, password, id_classe from etudiant"; $result = $conn-> query($sql); if ($result-> num_row > 0) { while ($row = $result-> fetch_assoc()) { echo ""; } echo "
id nom prenom password id_classe
". $row["id"] ." ". $row["nom"] ." " .$row["prenom"] ." " .$row["password"] ." " .row["id_classe"] ."
"; } else{ echo"0 result"; } $conn-> close(); ?>

and this is my code :
<!DOCTYPE html>
<html>
<head>
<title>table with database</title>
</head>
<body>
<table>
<tr>
<th>id </th>
<th>nom </th>
<th>prenom </th>
<th>password </th>
<th>id_classe </th>
</tr>
<?php
$conn =mysql_connect("localhost", "root", "", "db");
if ($conn-> connect_error) {
die("connection failed:". $conn-> connect_error);
}

$sql = "SELECT id, nom, prenom, password, id_classe from etudiant";
$result = $conn-> query($sql);

if ($result-> num_row > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>". $row["id"] ."</td><td>". $row["nom"] ."</td><td>" .$row["prenom"] ."</td><td>" .$row["password"] ."</td><td>" .row["id_classe"] ."</td></tr>";
}
echo "</table>";
}
else{
echo"0 result";
}
$conn-> close();
?>


</table>

</body>
</html>

PLEASE HELP I HAVE A PROJECT AND I NEED TO CONNECT DATA WITH CODE !! THANK YOU

Re: Display Data from MySQL Database into HTML Table using PHP

Posted: Sat Jun 27, 2020 7:46 pm
by shah.nawaraj.forum
Check out this post (viewtopic.php?f=4&t=4), may be it will help you.

Re: Display Data from MySQL Database into HTML Table using PHP

Posted: Sat Jun 27, 2020 10:46 pm
by imane chakri
my database's name is db
there are many tables in it, one of them called "etudiant"
and this table had infos : id, nom, prenom, password, id_classe . and all of theme had value
i think my code is correct i don't know where is the problem !
can you text me in my gmail to help me on this if you can ofc
[email protected]

Re: Display Data from MySQL Database into HTML Table using PHP

Posted: Sun Jun 28, 2020 8:06 am
by shah.nawaraj.forum
If browser return php code, that means php code is not running. Check out this post viewtopic.php?f=4&t=6