Hi, I working on my personal project on my own and I attempt to try and get the dropdownlist from mysql,php and html to work but it didn’t work.
This is what the actual result look like:
Here’s my actual code and it contains the comments:
<!DOCTYPE html>
<html>
<body>
<!--This is the form for the textbox firstname,lastname,password,email address and dropdownlist that will be call from the database-->
<form method="POST">
First name:<br>
<input type="text" name="FirstName">
<br>
Last name:<br>
<input type="text" name="LastName">
<br>Password:<br>
<input type ="text" name="Password">
<br>
Email Address:<br>
<input type="text" name="EmailAddress" value="" />
<br>
<!--This is the Role Name that will be populate from the mysql database in the php section-->
Role Name:<br>
<!--<input type="text" name="RoleName" value="2" /> -->
<select name='RoleName'>
<br><br>
<!--This is the submit button-->
<input type="submit">
<!--</form> -->
<?php
//connect to database
$connection = mysqli_connect("localhost", "user", "password", "construction", "3306");
//run the store procedure call getallroles for dropdownlist
$sql = mysqli_query($connection,
"CALL getallroles") or die("Query fail: " . mysqli_error()); //run your query
// That selectname RoleName came from the html section and the dropdownlist should work only from html5 section not
//php section I want to get of echo "<select name='RoleName'>"; // list box select command but I can't
//because its part of mysql database
echo "<select name='RoleName'>"; // list box select command
//This is the part where it fetches the RoleNames for Admin and User Names
while($row=mysqli_fetch_array($sql))
{ $select.='<option value="'.$row[0].'">'.$row[0].'</option>';
//Option values are added by looping through the array
}
echo $select;// Closing of list box
//This is the part where it prints out but the RoleName dropdownlist does not work
echo("First name: " . $_POST['FirstName'] . "<br />\n");
echo("Last name: " . $_POST['LastName'] . "<br />\n");
echo("Email Address: " . $_POST['EmailAddress'] . "<br />\n");
echo("Role Name: " . $_POST[$select] . "<br />\n");
?>
</select>
</form>
</body>
</html>