jvandal Posted May 4, 2007 Share Posted May 4, 2007 I added a dropdown field for field named subject. It displays at the bottom of the form. It doesn't add the value to the field , leaving it blank Any help will be appreciated jvandal //************ form with select drop down table ******************* <?php session_start(); if(!isset($_SESSION['iid'])) $_SESSION['iid'] = 1; $myid = $_SESSION['iid']; echo "views = ". $_SESSION['iid']; echo "this id is $myid<br>"; $conn = @mysql_connect("localhost", "root", "") or die(mysql_error()); echo ("Connect to HOST<br>"); $db = @mysql_select_db("usadb",$conn); echo ("connect to DB<br>"); ?> <HTML> <HEAD> <center><h1>Works Input Form</h1></center> <TITLE>INsert Form</TITLE> </HEAD> <body> <form action="<?php echo( $self ); ?>" method="post"> <P><strong>Subject/Person/:</strong><br> //************ select drop down table ******************* //************************************************* <?php $query="SELECT titlex,id FROM subjects"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=subjects value=''>Subject Name</option>"; // printing the list box select command //************ end select drop down table ******************* //*************************************************** while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[titlex]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> //************ field to be replaced select drop down table ********************************************** <input type= text name= "subjectid" size=10 > <input type= text name= "personid" size=10></p> <P><strong>Title/Startdate/Endhdate:</strong><br> <input type= text name= "title" size=50 > <P><strong>Start:</End Date ><br> <input type= text name= "startday" size=10> <input type= text name= "startmonth" size=10> <input type= text name= "startyear" size=10> <input type= text name= "endday" size=10> <input type= text name= "endmonth" size=10> <input type= text name= "endyear" size=10> <P><strong>Owner\Manager:</strong><br> <input type= text name= "owner" size=30 > <input type= text name= "manager" size=5 > <P><strong>Salery:</strong><br> <input type= text name= "salery" size=30 > <p><input type="submit" value="Add Works"></p> <p><a href="Adminmenu.htm?<?php echo( SID );?>">Back to Menu</a> <p><a href="../ushowworks.php?<?php echo( SID );?>">Back toPersons</a> ></p> </FORM> <?PHP if ($_POST[subjectid] || $_POST[title]) { //************ replace subject field with $nt[id} ******************* //********************************************************** $add_master = "insert into works values ('', '$nt[id]', $myid, '$_POST[title]', '$_POST[startday]', '$_POST[startmonth]', '$_POST[startyear]', '$_POST[endday]','$_POST[endmonth]','$_POST[endyear]', '$_POST[owner]', '$_POST[manage]', '$_POST[salery]')"; $rs = mysql_query($add_master); echo ("past sql<br>"); if ($rs) {echo ("added to work table<br>"); } else { echo ("NOT added to work able<br>"); } } ?> </body> </HTML> Link to comment https://forums.phpfreaks.com/topic/49938-inserting-dropdown-list-in-proper-place-in-form/ Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 Most of your html is not valid including your dropdown. echo "<option value='{$nt['id']}'>{$nt['titlex']}</option>"; Also note the quotes around the array key, and the {} around what is known as a complex variable (array with non numeric index). Link to comment https://forums.phpfreaks.com/topic/49938-inserting-dropdown-list-in-proper-place-in-form/#findComment-245128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.