HTML comments PHP out, but why? -
i'm trying fill select input data database. php code works, when try build html form wrecks up.
heres code (start.html):
[...] <form action="action.php" method="post"> <p>schueler:</p> <select name="schueler"> <?php $mysqli = new mysqli("localhost", "test", "test01", "noten"); $query = "select id, vorname, nachname schueler"; $result = $mysqli->query($query); while($row = $result->fetch_assoc()) { echo '<option value="' .htmlspecialchars($row['id']).'">' .htmlspecialchars($row['vorname']) .' '. htmlspecialchars($row['nachname']).'</option>'; } ?> </select> [...] but on loading page this:
<form action="action.php" method="post"> <p>schueler:</p> <select name="schueler"> <!--?php $mysqli = new mysqli("localhost", "test", "test01", "noten"); $query = "select id, vorname, nachname schueler"; $result = $mysqli--->query($query); while($row = $result->fetch_assoc()) { echo '<option value="' .htmlspecialchars($row['id']).'">' .htmlspecialchars($row['vorname']) .' '. htmlspecialchars($row['nachname']).'</option>'; } ?>" </select> [...] as can see, problem likely, php command commented when running page. can or provide ideas?
heres code (start.html):
rename file start.php in order let server know needs parsed php interpreter.
update (following comment empty <select> element):
an empty <select> element means while() loop not execute.
take @ generated source code (command view source in browser) , possible error or warning messages expect else (inside <select> element).
if there nothing there enable reporting , displaying of errors; put error_reporting(e_all); , ini_set('display_errors', '1'); on top of script.
add code check query result (if ($result != false)) before trying fetch rows it.
it's possible connection fails. check value of $mysqli->connect_errno right after create $mysqli. if not 0 connection failed. can find reason in $mysqli->connect_error.
also make sure table schueler contains data returned query.
Comments
Post a Comment