Built a html form in php and have 1 list box that is populated from mysql and 1 text box.
When submitting I do not get value from the dynamic list box but if i use normal option with value tag in the select, all is well.
Using "GET" the url shows no value for the listbox, only name= being empty. The textbox submits data ok. Any ideas appreciated.
Here,s the php code.
<?php
include "dbdetails.php"; // Database connection using PDO
try {
$link = new PDO('mysql:host='.$dbhost.';dbname='.$dbname, $dbusername, $dbpassword);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$sql="SELECT DISTINCT username FROM users_logon ORDER BY username ASC";
print "<h2>Add Record</h2>";
print "<form method='get' action='addrecord.php'>";
print "User Name: <select name='Uname' value=''>"; // list box select command
///print "<option value=''></option>"; // use if need first row empty
//Array or records stored in $row
foreach ($link->query($sql) as $row){
//print "<option value=$row[id]>$row[name]</option>";
print "<option value=>$row[username]</option>";
}
/*print "User Name: <select name='Uname' value=''>"; // list box select command
print "<option value='1'> standard</option>";
print "<option value='2'> 2-day</option>";
print "<option value='3'> overnight</option>";*/
print "<br />";
print "</select>";// Closing of list box
print "<br /><br />";
print "Pasword: <input type='text' size='8' maxlength='8' name='Pword'>";
print "<br /><br />";
print "<input type='submit' name='submit' value='Add' />";
print "</form>";
?>
Below the foreach i tried setting non dynamic option values and that returns the submit data ok.
print "<option value='$row[username]'>$row[username]</option>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.