Ok, this is what I have. <?php require_once('tb/connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); echo '<div id="box4">'; echo '<h2>Fabricators</h2>'; echo '<div id="fab1">'; echo '<h2>Fabricators</h2>'; $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'] . '"'; if($row['user'] == $user) { echo ' selected'; } echo '>' . $row['user'] . '</option>\n'; } ?> <body> <a href="http://kaboomlabs.com/testbed/box.zip">Right Click and Save link as... for Code</a> </body> Code (markup): What it needs to do is to show the name Andy Kahl which is already inside the database but it's not. Can someone look at this code and tell me why? Thanks in advance.
1. why don't place the h2, select, etc. part also in the <body> section??? (BTW that's not the problem with your script, just a notice) 2. the line where you select your DB : $mysqli->select_db('user'); Code (markup): and then your query : $result = $mysqli->query("SELECT * FROM user"); Code (markup): unless you use the SAME name for your database AND your TABLE (user), this could be the problem... 3. you haven't closed the select tag If I were you I'd try this : <body> <?php require_once('tb/connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); echo '<div id="box4">'; echo '<h2>Fabricators</h2>'; echo '<div id="fab1">'; echo '<h2>Fabricators</h2>'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('database_name'); $result = $mysqli->query("SELECT * FROM table_name"); echo "<select name='fab1'>"; while($row = $result->fetch_assoc()) { echo '<option value="' . $row['user_name'] . '"'; if($row['user_name'] == $user) { echo ' selected'; } echo '>' . $row['user_name'] . '</option>'; } echo "</select>"; ?> <a href="http://kaboomlabs.com/testbed/box.zip">Right Click and Save link as... for Code</a> </body> PHP: Good luck!
As for your question, the reason I didn't format this at all is because it is part of a much, much larger script. There is a bunch of formatting already involved with it, and right now this is just to show this script, and what it does, and what I want it to do, instead of making it look pretty I just tried the script, and I now get a blank pull down menu... never mind, I realized what you did, I'll get back on an answer in a second.
Ok, I tried your script, I am getting a little lost. Here is the issue. I have access to two tables in one database. The database name for this instance is DB1, the tables involved are user, and ncmr. Here are the fields and tables in question that are being used. In user, the field $user is being accessed, it has a list of all employees to create a pull down menu. in ncmr $fab1 is where the data from the table user is being posted to as record. What I need to do is this: If an name has been entered into $fab1 I need to have a pull down menu show said name as it's selected choice, but the pull down list is from user, not ncmr, so this is why I have links to two tables. And this is why I am getting stuck. Does this make any sense?