i have asked this question before but no one could find the solution so I'm asking again with updated code to see if anyone else can help me.
As the title says i am trying to create check boxes in my site however the values will come from the mysql database. i cant figure out where i have gone wrong as my php code wont execute.
I have a database called "my computer", table named “campus” and it has 2 coloumns called id and room.
Below is the screenshot of my database and the output of the code in the web browser
<?PHP
$hostname = "localhost";
$username = "root";
$password = "root";
$databaseName = "my computer";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<html>
<body>
<form name="aform">
Choose a room:
<?php
$sql = "SELECT * FROM `campus`";
$result = mysqli_query($sql);
mysqli_query($connect, $sql);
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<input type="checkbox" name="car" value="<?php echo $line['room'];?>" />
<?php
}
?>
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire