harkly Posted December 26, 2008 Share Posted December 26, 2008 I am trying to set up a form to update information for a user. There are a lot of different inputs and I have a few that I want drop downs. I am not sure how to do that. I can make a typical drop down that pulls the variable but I need to combine them (at least I think I do) here's my code that is working -- echo "<table border=0>"; echo "<tr><td valign=top><form method='post' action='updateArtist.php'><h5>Artist Id --</b><input type='text' name='artid' value='$artid'></td></tr>\n"; echo "<tr><td colspan=3><h5>Mediums Associated to --</b></td></tr> \n"; echo "<tr><td>1</td><td>2</td><td>3</td></tr>\n"; echo "<tr><td><input type='text' name='medid_1' value='$medid_1'><td><input type='text' name='medid_2' value='$medid_2'></td><td><input type='text' name='medid_3' value='$medid_3'></td></tr>\n"; echo "<tr><td><input type='submit' name='button' value='Update'></td></tr>\n"; echo "</form>\n"; echo "</table>"; here is what I want to change the, Mediums Associated to, so I can use a drop down box -- echo "<tr><td> \n"; echo "<b>Medium</b> <br><br>"; $result = mysql_query("SELECT * FROM medium order by medName") or die(mysql_error()); $num_rows=mysql_num_rows($result); if ($num_rows != "0") { echo "<form method='post' action='updateArtist.php'>"; echo "<select name='medium'>"; while ($r=mysql_fetch_array($result)) { $medName=$r["medName"]; $medid=$r["medid"]; $description=$r["description"]; $keywords=$r["keywords"]; $notes=$r["notes"]; echo "<option value='$medid_1' selected>$medName</option>"; } echo "</select>"; echo "<input type='hidden'>"; echo "</form>"; } echo "</td></tr>\n"; here's my entire code for the form -- //display the form echo "<table border=0>"; echo "<tr><td><img src='../image/$artid/$artid.jpg' border=0></td>\n"; echo "<tr><td valign=top><form method='post' action='updateArtist.php'><h5>Artist Id --</b><input type='text' name='artid' value='$artid'></td></tr>\n"; echo "<tr><td><h5>Name(s) --</b></td></tr> \n"; echo "<tr><td><h2>First</td> <td>Middle</td> <td>Last</td></tr><tr> \n"; echo "<tr><td><input type='text' name='firstName' value='$firstName'></td><td><input type='text' name='middleName' value='$middleName'></td><td><input type='text' name='lastName' value='$lastName'></td></tr>\n"; echo "<tr><td><h2>Full Name </td><td>Other Name --</td><td><h2>Called</td></tr>\n"; echo "<tr><td><input type='text' name='fullName' value='$fullName'></td><td><input type='text' name='called' value='$called'></td><td><input type='text' name='otherName' value='$otherName'></td></tr>\n"; echo "<tr><td colspan=3><h5>DOB/DOD --</b></td></tr> \n"; echo "<tr><td><h2>DOB Extra</td><td><h2>Date of Birth</td><td><h2>DOD Extra</td><td><h2>Date of Death</td></tr>\n"; echo "<tr><td><input type='text' name='dob_xt' value='$dob_xt'></td><td><input type='text' name='dob' value='$dob'></td><td><input type='text' name='dod_xt' value='$dod_xt'></td><td><input type='text' name='dod' value='$dod'></td></tr>\n"; echo "<tr><td><h5>Art Form --</td></tr><tr><td><input type='text' name='artform' value='$artform'></td></tr>\n"; echo "<tr><td colspan=3><h5>Movements Associated to --</b></td></tr> \n"; echo "<tr><td><h2>1</td> <td><h2>1</td><td><h2>3</td</tr>\n"; echo "<tr><td><input type='text' name='movid_1' value='$movid_1'></td><td><input type='text' name='movid_2' value='$movid_2'></td><td><input type='text' name='movid_3' value='$movid_3'></td></tr>\n"; echo "<tr><td colspan=3><h5>Mediums Associated to --</b></td></tr> \n"; echo "<tr><td>1</td><td>2</td><td>3</td></tr>\n"; echo "<tr><td><input type='text' name='medid_1' value='$medid_1'><td><input type='text' name='medid_2' value='$medid_2'></td><td><input type='text' name='medid_3' value='$medid_3'></td></tr>\n"; echo "<tr><td> \n"; echo "<b>Medium</b> <br><br>"; $result = mysql_query("SELECT * FROM medium order by medName") or die(mysql_error()); $num_rows=mysql_num_rows($result); if ($num_rows != "0") { echo "<form method='post' action='updateArtist.php'>"; echo "<select name='medium'>"; while ($r=mysql_fetch_array($result)) { $medName=$r["medName"]; $medid=$r["medid"]; $description=$r["description"]; $keywords=$r["keywords"]; $notes=$r["notes"]; echo "<option value='$medid_1' selected>$medName</option>"; } echo "</select>"; echo "<input type='hidden'>"; echo "</form>"; } echo "</td></tr>\n"; echo "<tr><td colspan=3><h5>Genres Associated to --</b></td></tr> \n"; echo "<tr><td><h2>1</td><td>2</td><td>3</td></tr>\n"; echo "<tr><td><input type='text' name='genid_1' value='$genid_1'></td><td><input type='text' name='genid_2' value='$genid_2'></td><td><input type='text' name='genid_3' value='$genid_3'></td></tr>\n"; echo "<tr><td colspan=3><h5>Period Assocaited with --</b></td><td> \n"; echo "<tr><td><input type='text' name='perid' value='$perid'></td></tr>\n"; echo "<tr><td><h5>Bio --</td><td><textarea rows='5' cols='20' wrap='physical' name='bio' value='$bio'> $bio</textarea></td></tr>\n"; echo "<tr><td><h5>Keywords --</td><td><textarea rows='5' cols='20' wrap='physical' name='keywords' value='$keywords'> $keywords</textarea></td></tr>\n"; echo "<tr><td><h5>Notes --</td><td><textarea rows='5' cols='20' wrap='physical' name='notes' value='$notes'> $notess</textarea></td></tr>\n"; if ($verified) echo "<tr><td><h5>Verified</h3></td><td><input type='checkbox' name='verified' value='1' checked></td></tr>\n"; else echo "<tr><td><h5>Verified</h3></td><td><input type='checkbox' name='verified' value='1'></td></tr>\n"; echo "<tr><td><input type='submit' name='button' value='Update'></td></tr>\n"; echo "</form>\n"; echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/138499-forms/ Share on other sites More sharing options...
gevans Posted December 26, 2008 Share Posted December 26, 2008 I don't really follow.which of these is your code and what do you want changed/help with? Link to comment https://forums.phpfreaks.com/topic/138499-forms/#findComment-724166 Share on other sites More sharing options...
harkly Posted December 27, 2008 Author Share Posted December 27, 2008 I have a form that updates my database. I want to be able to pull some information from a table and have it as a drop-down. I currently have it working where you can type the information in but I need to change it. I was able to create a form that pulls the info I need from a table and it now offers a selection. However I can not get that info to update. I know that I have done it wrong and need help going to the next step. this is my full code - - //display the form echo "<table border=0>"; echo "<tr><td><img src='../image/$artid/$artid.jpg' border=0></td>\n"; echo "<tr><td valign=top><form method='post' action='updateArtist.php'><h5>Artist Id --</b><input type='text' name='artid' value='$artid'></td></tr>\n"; echo "<tr><td><h5>Name(s) --</b></td></tr> \n"; echo "<tr><td><h2>First</td> <td>Middle</td> <td>Last</td></tr><tr> \n"; echo "<tr><td><input type='text' name='firstName' value='$firstName'></td><td><input type='text' name='middleName' value='$middleName'></td><td><input type='text' name='lastName' value='$lastName'></td></tr>\n"; echo "<tr><td><h2>Full Name </td><td>Other Name --</td><td><h2>Called</td></tr>\n"; echo "<tr><td><input type='text' name='fullName' value='$fullName'></td><td><input type='text' name='called' value='$called'></td><td><input type='text' name='otherName' value='$otherName'></td></tr>\n"; echo "<tr><td colspan=3><h5>DOB/DOD --</b></td></tr> \n"; echo "<tr><td><h2>DOB Extra</td><td><h2>Date of Birth</td><td><h2>DOD Extra</td><td><h2>Date of Death</td></tr>\n"; echo "<tr><td><input type='text' name='dob_xt' value='$dob_xt'></td><td><input type='text' name='dob' value='$dob'></td><td><input type='text' name='dod_xt' value='$dod_xt'></td><td><input type='text' name='dod' value='$dod'></td></tr>\n"; echo "<tr><td><h5>Art Form --</td></tr><tr><td><input type='text' name='artform' value='$artform'></td></tr>\n"; echo "<tr><td colspan=3><h5>Movements Associated to --</b></td></tr> \n"; echo "<tr><td><h2>1</td> <td><h2>1</td><td><h2>3</td</tr>\n"; echo "<tr><td><input type='text' name='movid_1' value='$movid_1'></td><td><input type='text' name='movid_2' value='$movid_2'></td><td><input type='text' name='movid_3' value='$movid_3'></td></tr>\n"; echo "<tr><td colspan=3><h5>Mediums Associated to --</b></td></tr> \n"; echo "<tr><td>1</td><td>2</td><td>3</td></tr>\n"; echo "<tr><td><input type='text' name='medid_1' value='$medid_1'><td><input type='text' name='medid_2' value='$medid_2'></td><td><input type='text' name='medid_3' value='$medid_3'></td></tr>\n"; // **** THIS IS WHERE I HAVE MODIFIED THE CODE TO GET A DROP DOWN BUT I NEED TO BE ABLE TO UPDATE THE TABLE AND ITS NOT WORKING **** echo "<tr><td> \n"; echo "<b>Medium</b> <br><br>"; $result = mysql_query("SELECT * FROM medium order by medName") or die(mysql_error()); $num_rows=mysql_num_rows($result); if ($num_rows != "0") { echo "<form method='post' action='updateArtist.php'>"; echo "<select name='medium'>"; while ($r=mysql_fetch_array($result)) { $medName=$r["medName"]; $medid=$r["medid"]; $description=$r["description"]; $keywords=$r["keywords"]; $notes=$r["notes"]; echo "<option value='$medid_1' selected>$medName</option>"; } echo "</select>"; echo "<input type='hidden'>"; echo "</form>"; } echo "</td></tr>\n"; echo "<tr><td colspan=3><h5>Genres Associated to --</b></td></tr> \n"; echo "<tr><td><h2>1</td><td>2</td><td>3</td></tr>\n"; echo "<tr><td><input type='text' name='genid_1' value='$genid_1'></td><td><input type='text' name='genid_2' value='$genid_2'></td><td><input type='text' name='genid_3' value='$genid_3'></td></tr>\n"; echo "<tr><td colspan=3><h5>Period Assocaited with --</b></td><td> \n"; echo "<tr><td><input type='text' name='perid' value='$perid'></td></tr>\n"; echo "<tr><td><h5>Bio --</td><td><textarea rows='5' cols='20' wrap='physical' name='bio' value='$bio'> $bio</textarea></td></tr>\n"; echo "<tr><td><h5>Keywords --</td><td><textarea rows='5' cols='20' wrap='physical' name='keywords' value='$keywords'> $keywords</textarea></td></tr>\n"; echo "<tr><td><h5>Notes --</td><td><textarea rows='5' cols='20' wrap='physical' name='notes' value='$notes'> $notess</textarea></td></tr>\n"; if ($verified) echo "<tr><td><h5>Verified</h3></td><td><input type='checkbox' name='verified' value='1' checked></td></tr>\n"; else echo "<tr><td><h5>Verified</h3></td><td><input type='checkbox' name='verified' value='1'></td></tr>\n"; echo "<tr><td><input type='submit' name='button' value='Update'></td></tr>\n"; echo "</form>\n"; echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/138499-forms/#findComment-724258 Share on other sites More sharing options...
thetooth Posted December 27, 2008 Share Posted December 27, 2008 you need to set the `value` in each form element to the resulting var called from the database, as for the drop downs you may have to list them with an array and then use a string match to make then drop down auto select the item Link to comment https://forums.phpfreaks.com/topic/138499-forms/#findComment-724261 Share on other sites More sharing options...
harkly Posted December 27, 2008 Author Share Posted December 27, 2008 any examples that may help? or a web site I can check out? Very new to this stuff Link to comment https://forums.phpfreaks.com/topic/138499-forms/#findComment-724283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.