I’ve come a long way with this script, but I am running into a new issue now. The data has posted correctly, but when I attempt to view the edit the pull down menu now shows –None– even though the first name, “Any Kahl” is shown in the database.
The code below is what I’m using, I can’t seem to understand why it’s not pulling data the correct way. Any help would be greatly appreciated.
if ($row['fab1']=="--None--")
{
echo'<div id="fab1">';
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$mysqli->select_db('user');
$result = $mysqli->query("SELECT * FROM user");
echo "<SELECT name='fab1'>\n";
while($row = $result->fetch_assoc())
{
echo "<option value='{$row['user']}'>{$row['user']}</option>\n";
}
echo "</select>\n";
echo '</div>';
}
else
{
echo'<div id="fab1">';
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$mysqli->select_db('user');
$result = $mysqli->query("SELECT * FROM user");
echo "<SELECT name='fab1'>\n";
while($row = $result->fetch_assoc())
{
echo "<option value='{$row['user']}'>{$row['user']}</option>\n";
}
echo "</select>\n";
echo '</div>';
}
If you don’t wrap your code blocks in curly braces, the if statement will only apply to the first line immediately following it (in your case:
echo'<div id="fab1">'), anything after that will execute regardless of whether your statement evaluated to true.You should wrap your if statement in curly braces: