thewarchief Posted October 19, 2009 Share Posted October 19, 2009 Hello, I am trying to create a table in which each box of the table will contain a dropdown menu and a textbox. Now, I know how to do this using bad programming technique by essentially copying and pasting dozens of lines of php code into each box, but I am fairly certain there is a better way. What I want to do is create an html file that contains the table, and within each box of the table it has a form that will use php code from a different file. Here is what I currently have: The html code (note: this is only from one box of the table... all of the boxes are the same): <td align="center"><p class="style9"> <form name="myform" action="lottotable.php" method="post"> <label for="frmcounty"></label> </form> <form id="formTextBox1" name="form1TextBox1" method="post" action="lottotable.php"> <INPUT type="text" value="" name"txtInput" id="txtInput" /> </select> </form> </p> Here is the php code: <?php $link = mysql_pconnect("********", "********", "********") or die("pconnectfailed!" .mysql_error()); mysql_select_db("albert123_lotto", $link) or die("unable to select db" .mysql_error()); $sql = "SELECT lottoName FROM `Lottos` ORDER BY `lottoName` "; $result = mysql_query($sql) or die("could not retrieve" .mysql_error()); echo '<select name="'.frmcounty.'" id="'.frmcounty.'"><option value="">Game Type:</option>'; while($info = mysql_fetch_array($result,MYSQL_ASSOC)) { foreach($info as $value) { echo '<option value=".$value.">'.$value.'</option>'; } } ?> <?php session_start(); extract($_POST); print($txtInput); $linkTextBox1 = mysql_pconnect("********", "********", "********") or die("pconnectfailed!" .mysql_error()); mysql_select_db("albert123_lotto", $linkTextBox1) or die("unable to select db" .mysql_error()); $sqlTextBox1 = "UPDATE store_".$store_num."_inv SET serialStart = '$txtInput' WHERE lottoName = '$selectResult'"; $resultTextBox1 = mysql_query($sqlTextBox1, $linkTextBox1); if(!$resultTextBox1) { echo mysql_error(); exit; } mysql_free_result($resultTextBox1); mysql_close(); ?> I am certain that some of this code looks abnormal, as I am essentially trying to do this having no prior PHP education. Thank you for any information given. Link to comment https://forums.phpfreaks.com/topic/178252-html-forms-using-php/ Share on other sites More sharing options...
zq29 Posted October 19, 2009 Share Posted October 19, 2009 From what you have posted, it is difficult to understand what you are trying to achieve. What is the end result that you are after? Without knowing any more, I'd suggest you use some form of loop to create your table cells. For example... echo "<table cellpadding='4px' cellspacing='0px' border='1px'>"; for($i=0; $i<11; $i++) { echo "<tr><th>Line $i</th><td><input type='text' name='line[$i]' value='' /></td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/178252-html-forms-using-php/#findComment-939990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.