Reputation: 141
<select name="mac">
<?php
$sql = mysqli_query($conn, "SELECT name FROM wifi_mac");
while ($row = $sql->fetch_assoc()){
echo "<option value=\"mac\">" . $row['name'] . "</option>";
}
?>
</select>
above code has an issue instead of posting a mac value from the table wifi_mac it sends a "mac" string instead of actual value from the table.
table: wifi_mac columns: varchar id, varchar name, varchar mac, varchar model
Upvotes: 0
Views: 35
Reputation: 196
You haven't selected the mac
column in your query, and it would return a mac string since you just put the "mac"
which is a string
, so try this:
<select name="mac">
<?php
$sql = mysqli_query($conn, "SELECT name, mac FROM wifi_mac");
while ($row = $sql->fetch_assoc()){
echo "<option value=\"" . $row['mac'] . "\">" . $row['name'] . "</option>";
}
?>
</select>
Upvotes: 1
Reputation: 20855
That's because you output only the string mac. Should have been $row['mac']
<select name="mac">
<?php
$sql = mysqli_query($conn, "SELECT name FROM wifi_mac");
while ($row = $sql->fetch_assoc()){
echo "<option value=\"".$row['mac']."\">" . $row['name'] . "</option>";
}
?>
</select>
Upvotes: 1