So basically I have a database and inside that I have a table named drivers which is structured as:
Drivers: id forename surname nationality team_id
Now I want to pull the Forename and Surname in a HTML Form. I need a submit button and a drop down list input. The drop down will contain the names of the drivers and the form will submit via a GET method.
How would I possibly go about doing this? This is what I have so far however it doesn't seem to work and I haven't
<?php
$con=mysqli_connect("hostname","username","password","dbname");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Write out our query.
$link=mysqli_connect(hostname,username,password,dbname));
$result = mysqli_query( "SELECT * FROM Drivers");
// Execute it, or return the error message if there's a problem.
$result = mysqli_query($query) or die(mysqli_error());
$dropdown = "<select name='Drivers'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "
<option value='{$row['forename']}'>{$row['surname']}</option>";
}
$dropdown .= "
</select>";
echo $dropdown;
?>
I'm quite new to PHP so apologies for such a noob question.
Try this
<form action="" method="get">
<?php
$con=mysqli_connect("hostname","username","password","dbname");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Write out our query.
$link=mysqli_connect(hostname,username,password,dbname);
$result = mysqli_query("SELECT * FROM Drivers");
// Execute it, or return the error message if there's a problem.
$result = mysqli_query($query) or die(mysqli_error());
$dropdown = "<select name='Drivers'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "
<option value='{$row['forename']}'>{$row['surname']}</option>";
}
$dropdown = "
</select>";
echo $dropdown;
?>
<input type="submit" value="Send">
</form>
Problem came from here:
$dropdown .= "
</select>";
FIXED