itgranny Posted October 7, 2015 Share Posted October 7, 2015 I have a mysql table where the columns are id, name, username and password. I have it working so that names are in the dropdown, its its posting it, but is there a way to make it display the name, yet post the id? The following is what I have done, it works, but the id is just a number and means nothing to the user. When I trade that out for name, the user is able to read and understand it, but some of the names have spaces, punctuation ect, and I would like to have it to be able to look up the username and password once the main table is to be updated. $sql = "SELECT * FROM stud ORDER BY studName"; $result = mysql_query($sql); echo "<td> <select name='id'>"; while ($row = mysql_fetch_array($result)) { echo "<option style='text-transform: uppercase;'" . $row['id'] . "'id='dropdown' >" . $row['id'] . "</option>"; } echo "</select></td></tr>"; echo "<tr><td><input id='submit' name='submit' type='submit' value='Submit'></td></tr></table> </form>"; basically what I want is this but I can't get this to work. $sql = "SELECT * FROM stud ORDER BY studName"; $result = mysql_query($sql); echo "<td> <select name='id'>"; while ($row = mysql_fetch_array($result)) { echo "<option style='text-transform: uppercase;'" . $row['id'] . "'id='dropdown' >" . $row['name'] . "</option>"; } echo "</select></td></tr>"; echo "<tr><td><input id='submit' name='submit' type='submit' value='Submit'></td></tr></table> </form>"; Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2015 Share Posted October 7, 2015 if you have <option value='$id'>$name</option> then the name is displayed but the id (value) is posted. Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 7, 2015 Share Posted October 7, 2015 (edited) The problem is your missing value=" " (I think that's what @Barand was pointing out.) You can also clean up your php by letting Mysql do the uppercase SELECT id,UPPER(name) FROM stud ORDER BY studName and by using parenthesis instead of escaping your variables. echo "<option value=\"{$row['id']}\" id=\"dropdown\" >{$row['name']}</option>"; Edited October 7, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.