html - How to update a form dropdown menu with PHP? -



html - How to update a form dropdown menu with PHP? -

i have been trying update form's dropdown menu list of entries have in database. database has been created mysql. have been looking solution over, , not sure why, none has worked. latest version have used this:

<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <form method="post" action="submitrequest.php"> staff id: <br> <input type="text" name="stfid" value=""> <br><br> e-mail: <br> <input type="text" name="email" > <br><br> select choice: <br> <select name="choice" value="select" size="1"> <?php $server= '*******'; $user = '*******'; $password = '*******'; $database = '********'; $conn = new mysqli($server, $user, $password, $database); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select * choicesgiven"; $result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $id=$row["id"]; $titles=$row["ctitle"]; $options.="<option value=\"$id">".$titles; } $conn->close(); ?> <option> <? echo $options ?> </option> </select> <br><br> <input type="submit" name="submit" value="submit"> </form> </body>

i appreciate if help me this, have been trying access around week.

i not sure if improve utilize html file format or create php (if possible @ all), comment or help in advance.

i'm not pro php or html, again, tips / help / assistance appreciated.

update:

thanks @funkdoc , @len_d, however, when used either answers, didn't work. used main php chunk in separate php file, , got error (not sure if it's of use:

fatal error: phone call fellow member function query() on non-object in /home/u309965349/public_html/test2.php on line 11

the code in line 11 is:

$result = $mysqli->query($sql) or die ($mysqli->error);

still searching.....

update 2: used php chunk (the main chunk in middle) , saved php file. when ran it, , echoed $options, got list wanted, when utilize in html document update select part of form, still same $titles, means html syntax not correct.

thank help in advance.

update 3:

to elaborate on above update, utilize php chunk in separate .php file followed:

<?php $server= '*******'; $user = '*******'; $password = '*******'; $database = '********'; $conn = new mysqli($server, $user, $password, $database); $sql = "select * choicesgiven"; $result = $conn->query($sql) or die ($conn->error); $options; while ($row = $result->fetch_object()) { $id=$row->id; $titles=$row->ctitle; // debug_to_console ($id); $options.="<option value='".$id."'>".$titles."</option>"; } echo $options; $conn->close(); ?>

and managed options perfectly. html adding above code html form:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <p><span class="error">* required field.</span></p> <form method="post" action="submitrequest.php"> staff id: <br> <input type="text" name="stuid" value=""> <br><br> e-mail: <br> <input type="text" name="email" > <br><br> select choice: <br> <select name="choice" value="select"> <?php $server= '*******'; $user = '*******'; $password = '*******'; $database = '********'; $conn = new mysqli($server, $user, $password, $database); $sql = "select * choicegiven"; $result = $conn->query($sql) or die ($conn->error); $options; while ($row = $result->fetch_object()) { $id=$row->id; $titles=$row->ctitle; // debug_to_console ($id); $options.="<option value='".$id."'>".$titles."</option>"; } } echo $options; $conn->close(); ?> <? echo $options ?> </select> <br><br> <input type="submit" name="submit" value="submit"> </form> </body> </html>

and thing in dropdown menu this: ".$titles."

many , please allow me know if can figure out :)

update 4:

i have tried this:

while ($row = mysql_fetch_array($result)) { $id=$row->id; $titles=$row->btitle; // debug_to_console ($id); echo '<option value="'.$id.'">'.$titles'</option>'; }

you mixing mysqli , mysql commands. edit these lines:

$result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_array($result))

to:

$result = mysqli_query($conn,$sql); while mysqli_fetch_array($result);

also, alter this:

while ($row = $result->fetch_object())

to this:

while ($row = $result->fetch_array())

php html mysql forms

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -