Dan06 Posted September 24, 2008 Share Posted September 24, 2008 I would like to create a form generated on information stored in a mysql table. What I would like to do is store text (which will be used as options in a form) in a mysql table and then have a pull this information (the options) and create a form made up of checkboxs. Once the user selects one or more checkboxs the information is inserted/updated in another table (the user profile table). Retrieving the options text and displaying them is straight forward enough, but how do you convert the text into a checkbox with a label and place it in a form? Anyone have any ideas or suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/125701-how-do-you-create-a-form-using-data-stored-in-table/ Share on other sites More sharing options...
rarebit Posted September 24, 2008 Share Posted September 24, 2008 it's a true or false issue, to be checked or not <input type='checkbox' name='check' value='yes' checked> The option is yours! Quote Link to comment https://forums.phpfreaks.com/topic/125701-how-do-you-create-a-form-using-data-stored-in-table/#findComment-649962 Share on other sites More sharing options...
Dan06 Posted September 25, 2008 Author Share Posted September 25, 2008 I've been able to create a form that displays checkboxs and labels from data stored in a table, but I can't seem to get this dynamic form to update data in the target table. Below is the code I've put together. Anyone with ideas or suggestions on how to fix the problem of updating the target table with the dynamic form information, please let me know. Thanks. mysql_select_db($database_dbConnection, $dbConnection); $query_ProdType = "SELECT TypeName FROM producttype"; $query_limit_ProdType = sprintf("%s LIMIT %d, %d", $query_ProdType, $startRow_ProdType, $maxRows_ProdType); $ProdType = mysql_query($query_limit_ProdType, $dbConnection) or die(mysql_error()); $row_ProdType = mysql_fetch_assoc($ProdType); mysql_select_db($database_dbConnection, $dbConnection); $query_ServType = "SELECT TypeName FROM servicetype"; $query_limit_ServType = sprintf("%s LIMIT %d, %d", $query_ServType, $startRow_ServType, $maxRows_ServType); $ServType = mysql_query($query_limit_ServType, $dbConnection) or die(mysql_error()); $row_ServType = mysql_fetch_assoc($ServType); if ((isset($_POST["ListingForm"])) && ($_POST["ListingForm"] == "ListingForm")) { $updateSQL = sprintf("UPDATE businessprofile SET ProductType=%s, ServiceType=%s WHERE Id=" . "'" . $_SESSION['Reg'] . "'", GetSQLValueString($row_ProdType['TypeName'], "text"), GetSQLValueString($row_ServType['TypeName'], "text")); mysql_select_db($database_dbConnection, $dbConnection); $Result1 = mysql_query($updateSQL, $dbConnection) or die(mysql_error()); $updateGoTo = "listingregister.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration</title> <table width="100%" border="1" cellspacing="0" bordercolor="#000000"> <tr> <td><div id="ProdTbl"> <p><strong>Which Type of Products?</strong></p> <p> </p> <table border="1" align="center"> <?php do { ?> <tr> <td><form action="<?php echo $editFormAction; ?>" id="ProdTypeSelection" name="ProdTypeSelection" method="post"><input type="checkbox" name = "$row_ProdType['TypeName']" id="$row_ProdType['TypeName']" value="$row_ProdType['TypeName']"/> <input name="ListingForm" type="hidden" id="ListingForm" value="ListingForm" /> </form></td> <td><?php echo $row_ProdType['TypeName']; ?></td> </tr> <?php } while ($row_ProdType = mysql_fetch_assoc($ProdType)); ?> </table> <p> </p> </div> <div id="ServTbl"> <p><strong>What Type of Services?</strong></p> <p> </p> <table border="1" align="center"> <?php do { ?> <tr> <td><form action="<?php echo $editFormAction; ?>" id="ServTypeSelection" name="ServTypeSelection" method="post" > <input type="checkbox" name = "$row_ServType['TypeName']" id="$row_ServType['TypeName']" value="$row_ServType['TypeName']"/> <input name="ListingForm" type="hidden" id="ListingForm" value="ListingForm" /> </form></td> <td><?php echo $row_ServType['TypeName']; ?></td> </tr> <?php } while ($row_ServType = mysql_fetch_assoc($ServType)); ?> </table> <p> </p> </div> <center><input name="ListingSave" type="submit" id="ListingSave" value="Save" /></center></td> </tr> </table> </div> </div> <!-- end #footer --> <!-- end #container --> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/125701-how-do-you-create-a-form-using-data-stored-in-table/#findComment-650567 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.