I've seen at least a few duplicate questions regarding this already but for some reason I can't get the data to show up in the menu. The drop down menu is just blank.
The table is "Colleges2". The data I am trying to fetch is in a column called "Name". So it basically fetches and displays a list of Names from the Colleges2 table.
mysql_connect('localhost', '', '') or die(mysqli_error()) ;
mysql_select_db('Colleges2');
$sql = "SELECT Name FROM Colleges2";
$result = mysql_query($sql);
?>
<select name="Name" id="">
<?php
while ($row = mysql_fetch_array($result)) {
$Name = $row['Name'];
echo "<option value='" .$row['Name']. "'>" .$row['Name']. "</option>";
} ?>
</select>
I am probably not using the latest mysqli code....forgive me for that. I keep seeing posts and tutorials that use either mysql or mysqli.
UPDATED:
<?php
$sql = "SELECT Name FROM Colleges2";
$conn = new mysqli("localhost", "", "") or die("Failure!") ;
$stmt=$conn->query($sql);
?>
<select name="Name" id="">
<?php
while ($row = $stmt->fetch_assoc() ) {
$Name = $row['Name'];
echo "<option value='" .$Name. "'>" .$Name. "</option>";
} ?>
</select>
SECOND UPDATE (THIS ONE WORKED):
<?php
//$host = "localhost:3306";
//$db_name="univers1_test";
//$user = "univers1_admin";
//$pass = "B@ctad89";
//$conn = new mysqli($host, $user, $pass, $db_name) or die("DB Connection failed!!");
mysql_connect("localhost:3306", "", "") or die(mysql_error()) ;
mysql_select_db("univers1_test") or die(mysql_error()) ;
$sql = "SELECT Name FROM Colleges2";
$result = mysql_query($sql) or die(mysqli_error()) ;
//$stmt=$conn->query($sql);
?>
<select name="Name" id="">
<?php
while ($row = mysql_fetch_array($result)) {
?>
<option value="<?php $row['Name']; ?>"><?php echo $row['Name']; ?> </option>
<?php
} ?>
</select>