PHP - Handling Multiple Dynamic Forms On One Page.
Hey all,
This question is coming forth of another topic, but since that topic is not really about this issue, I posted this new topic. Okay, so I made a table, and each row is generated with a WHILE loop. In this while loop, there's also a form generated for each row/record, for updating them seperately. I'm having trouble with naming those forms to process them seperately. I could name them like name="form20110001", with the number being the record's id. But since there can be gaps between id's, how can I retreive them efficiently? And I want them to process all on a single process page, obviously. How can I do this easily? Can someone give me a concise example? Would appreciate it a lot. Thanks Similar TutorialsHi, I've tried to follow a couple tuts on multi-page forms using php. The reason I'm doing it is that I'd like to create a mock-job application form for my students at school. This would be too long to have on one page. Anyway, I've created the most simple form I could think of and was hoping someone could help me out and show me how to get the info from page 1 to 2, then the info from pages 1 and 2 to 3, and then submit the info from pages 1, 2 and 3 to the database. Page 1 asks for firstname, page 2 asks for lastname, and page 3 asks for email address. The fourth page is the one that processes the form. Page 1: (app_form_1.php) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_2"> Firstname: <label> <input type="text" name="firstname" id="firstname" /> </label> </form> <p> <label> <input type="submit" name="Continue" id="Continue" value="Continue" /> </label> Page 2 (app_form_2.php) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_3"> Lastname: <label> <input type="text" name="firstname" id="firstname" /> </label> </form> <p> <label> <input type="submit" name="Continue" id="Continue" value="Continue" /> </label> Page3 ( app_form_3.php ) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_process"> Email address: <label> <input type="text" name="emailaddress" id="emailaddress" /> </label> </form> <p> <label> <input type="submit" name="submit" id="Submit" value="Submit" /> </label> Page 4 (app_form_process.php ) Code: [Select] <?php global $_POST; $firstname = $_POST["firstname"] ; $lastname = $_POST["lastname"]; $emailaddress = $_POST["emailaddress"]; //**********************SEND TO DATABASE**************************** //MySQL Database Connect include 'mysql_connect.php'; $query = "INSERT INTO application_form (firstname, lastname, emailaddress)" . "VALUES ('$firstname', '$lastname', '$emailaddress')"; //if($query){echo 'data has been placed'} mysql_query($query) or die(mysql_error()); ?> Any help is much appreciated. Thanks, Dave Hey guys, im new to php and have become stuck with having more than one html form/submit that will relays to another piece of code to view something At the moment my first form works but once i submit my second form it relays back to the first form how can i prevent this so i can have many submit forms on one php page? Thanks Code: [Select] <?php $dbname = $_POST['dbname']; $tblname = $_POST['tblname']; checksubmit( $dbname); function checksubmit( $dbname){ if(isset($_POST['enter'])) { checkform( $dbname); } else { page1( $dbname); } } function checkform ($dbname){ if(empty($_POST['dbname'])){ echo 'fill out database name'; } else page2( $dbname ); } function page1( $dbname){ echo " <form method='post' action=''> <table> <tr> <td>Database name:</td><td><input type='text' name='dbname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='enter' value='enter' /></td> </tr> </table> </form> "; } function page2( $dbname ){ echo " <form method='post' action=''> <table> <tr> <td>Table Name:</td><td><input type='text' name='tblname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='return' value='return' /></td> </tr> </table> </form> "; if(isset($_POST['return'])) { page3( $dbname ); } } function page3( $dbname ) { echo 'I want to make it here'; } ?> Hi I have put together a options page for the script that I have been working on. I have 1 options page where there options are divided into 4 jQuery tabs with there own save button. The options in each tab are posted using Ajax to their own separate file like process.php, process1.php etc. My question is there a way to place all the processing code in one file and if so would this affect the load on the server? Would each form be better off having their own page for processing? For example: Code: [Select] <form id="options_1" action="process1.php" method="post" > <!-- this is form 1 that is processed with process1.php --> </form> <form id="options_2" action="process2.php" method="post" > <!-- this is form 2 Can this form be processed using process1.php instead of process2.php --> </form> <form id="options_3" action="process3.php" method="post" > <!-- this is form 3 Can this form be processed using process1.php instead of process3.php --> </form> Hi, I have an HTML form created using Dreamweaver and now I need a script to handle the form processing. Basically what I need is for the form data received from the webpage to be organized in an email and then sent to me. I would also like to display a thank you message in the browser so the user knows it was received. I was planning to do this using CGI but a colleague suggested that CGI is old school and nowadays a developer would use PHP for this task. Is PHP the right solution for this project? The examples I have found so far always include the HTML for the form and the script needed to handle it in one file. In my case, I have an HTML form already in place and need it to work with a script to perform the email function. I know I need to set "Action=" on my webpage to point to the PHP script but what would the code look like if no HTML is needed? I hope this makes sense... Thanks for your help! Rob I am creating a user inbox system. I am retrieving all the unread messages. Each message row contains a "reply" form. So say I have 10 messages showing on a single page. That's 10 forms. What I would like to know is how can I submit any one of the 10 forms and not have it affect the remaining 9 forms? Here is the basic code. if(isset($_POST['submit'])) { $post_message = trim($_POST['message']); $errors = array(); $db->beginTransaction(); if(empty($post_message)) { $errors[] = 'The message field can not be empty!'; } if(empty($errors)) { $db->commit(); echo 'success'; } else { $db->rollBack(); } } <form action="" method="post"> <fieldset> <textarea name="message" maxlength="10000" placeholder="What would you like to say?"></textarea> </fieldset> <fieldset> <input type="submit" name="submit" value="Submit" /> </fieldset> </form>
Hello All, I am building a web based data entry project for my University Recycling Department 1) In the first level the user will enter the number of "rows" that he has to enter it can be any number form 4- 10 . Each row will contain "Vendor Name","Date","Net Recycled Weight" 2) Depending on the number of rows entered by the user I am generating a table structure that has 2.1) A <select> containing vendor names(I am querying for this and then storing the result in an Associative Array and then parsing it for select in every way) 2.2) A text box for the date 2.3) A text box for the Net Recycled Weight ------------------------------------------------ Here is the logic I have implemented so far <html> <head></head> <body> <form name = "form1" method = "post"> <select>HERE THE USER CAN SELECT THE NUMBER OF ROWS HE WANTS TO ENTER</select> <input type = "submit" value = "submit1" name = "submit1"> </form> <body> </html> <?php if(submit1 has been clicked ) { //HERE I AM GENERATING A DYNAMIC FORM BASED ON THE NUMBER OF ROWS COUNT <form name = "form2" method = "post"> echo <table> echo <tr> echo<td>VENDOR</td> echo<td>DATE</td> echo<td>NET RECYCLED WEIGHT</td> echo </tr> for(IT ITERATES TILL I GENERATE THE NUMBER OF ROWS THAT HAS TO BE ENTERED) { I AM GENERATING ROWS HERE } echo <input type = "submit" name = "submit2" value = "submit2"> echo</table> </form> HOW CAN I ACCESS THE POST METHOD OF FORM 2 } ?> MY PROBLEM --------------- I WANT TO KNOW THE FOLLOWING 1) It this the correct way to do it 2) how can I access the data entered in each dynamic row as I have to validate it and then enter the data in MySql 3) I am not sure how I will access the submit button event of the dynamically generated form I hope I can get some help Thanks, Marisha My employer asked if I could change an existing contact form on their website to allow clients to enter their Social Security Number along with the normal contact information if the client decide to do so, instead of going through the motion of physically send in the form via snail mail, fax, or in person (like it is currently handled). But since this piece of information is of such delicate nature, I wonder how I should approach this from both a legal standpoint and from a programming standpoint. The form currently sends the information entered by the user to an inbox with mail(), so my initial thought was to somehow encrypt the information, limiting the risk of someone getting a hold of this information once the use user clicks "Send". But is full blown SSL really necessary for this? Are there easier options? And what should I think about before enabling this? I've searched and found numerous examples for creating dynamic forms using PHP and MySQL; however, each seems to be different and I have been unsuccessful with all of them. What I get is an empty pulldown menu instead of the contents from the MySQL table. I've worked this till I'm blue in the face and am now turning to the forums for help. I'm developing/testing code in NetBeans 8.0.2. Here is my code (name of file is 'domains.php': <body> <form method="post" action=""> <select id="domain" name="domain"> <?php // define connection variables $DBServer = "localhost"; // server name or IP address $DBUser = "xxxxxxxxx"; $DBPass = "xxxxxxxxx"; $DBName = "country"; $DBPort = "3306"; // I include the port because I have two instances of MySQL - the other is 3309 // create a connection to mysql $conn = mysqli_connect ($DBServer, $DBUser, $DBPass, $DBName, $DBPort); // check to see if a connection was made and, if yes, proceed if (mysqli_connect_errno()) { // connection failed echo "Database connection failed: " . mysqli_connect_error(); } // the domain query to get all domain names $domainQuery = "select domains from domains_subdomains_cop"; // run the query -- this works elsewhere to display the contents of a table $resultD = mysqli_query($conn, $domainQuery) or die ("Query to get data from domain failed: " . mysql_error()); // with the exception of a pulldown menu, the while loop works well to display all records, etc. // I've seen examples with MYSQLI_ASSOC and without and I've tried both without success - I use it because I // haven't had any issues elsewhere in my program while ($row=mysql_fetch_array($resultD, MYSQLI_ASSOC)) { $domainName=$row[DOMAINS]; // DOMAINS is the table attribute I'm trying to pull echo "<option> $domainName // I accidentely put a ';' here once and that did show up in the pulldown menu </option>"; } ?> </select> </form> </body> In advance, thank you for any help/insight you can provide!!! Nick. Please help me with some guidance. I want to allow users to create their own html forms by choosing different form elements (textfields, textareas, lists, ratios, etc) I guess something similar to http://wufoo.com/ but much more basic. I'm having some trouble deciding which approach I should take. Database tables or files? For tables I was thinking to create a table for each form element, e.g TEXTFIELD TABLE ID TEXTFIELD_NAME USER TEXTAREA TABLE ID TEXTAREA_NAME USER etc for all form elements and then just query all of them with.. WHERE user=$user Or should I generate php files on the server for each form created? Hello. I have a web page that has several operations on it, and I'm not sure the best way to design it. This is a subscription page were a user can choose different renewal plans. Before a certain date, the user can "renew" for a certain lower price (operation #1), or he/she can "upgrade" for a certain lower price (operation #2). After a certain date, the user can choose from one of three plans (operation #3, #4, or #5). The way I have things design for the "after" part is just creating a form for each one, so that when a user chooses one of them, then I can take the appropriate actions. My question is this... 1.) Is it okay to have five forms on the one web page to more clearly delineate each request/operation? 2.) Or should I create one form, and then assign a hidden form value to each button so I know how to handle the selection?
Edited July 25, 2020 by SaranacLake Hi guys, I'm reviewing a piece of small web application and the current application does not have any error / exception handling capability. If there is any error, it would simply show an error message followed by die;. I'm planning to implement a simple exception handling class to handle the errors. What I'm thinking is a simple redirect when an error is being caught together with an error code that correspond to an error message in a simple flat text file. The error page will then show an error message that corresponds to the code. Here's what I have so far. Would appreciate if the PHP experts here would give simple pointers to enhance it. <?php class MyException extends Exception {} try { throw new MyException("error.php"); } catch (MyException $e) { $file = $e->getMessage(); header("Location: $file?e=1"); } ?> This is what I have on my error.php page <?php $errorcode = $_GET['e']; function getErrorMessage($errorcode) { $errors = file("english.txt"); foreach ($errors as $error) { list ($key,$value) = explode(",",$error,2); $errorArray[$key] = $value; } return $errorArray[$errorcode]; } echo "Test <br />"; echo getMessageMap($errorcode); ?> As you can see here, exception class would redirect user to error.php if an error is caught together with a GET variable on the URL. On error.php page, it would GET the error code and then run it through a function to get the error message of the corresponding error code and then echos it out. Was wondering if this is a good practice? My ultimate goal here is to avoid displaying the error message itself on private includes file. Thank you in advance for your suggestions. Hello! I've got several forms on one page that use the same variable names for input values. (Say, form1, form2, and form3). I'm using javascript to show only one of the forms based on a selection (say British, American, Canadian). How can I write code which will tell the page to ONLY look at the variables from a particular form when I hit the submit button for one of the forms? Thanks so much.... Hi I have a script that pulls all records out of the database, each record is within a form with no name which results with a lot of forms with essentially the same name. I have an hidden field with the accID which I use to delete the record. This does what I want it to do but have read that you should avoid having mutliple forms, I guess for validation. I know I could do this with a link and use GET, but would rather not having this action showing the details of the deletion in the URL. Is multiple forms so bad? Thanks I continue to have problems with this issue - primarily relates to the the placement of the code for processing the 2nd form on a page. This is what i wish to do: a. Form 1 - Select a User b. For selected user, list all the records c. Form 2 - Choose 1 record from the list. d. Update the record. Here's what i have so far. I've just put the structure out here as the error comes up when form 2 tries to get processed . I dont know if the issue is with the way i 've named the forms or the submit buttons. All pointers appreciated. Many thanks. Swati <? (processing form1) =================== if($_POST['submit-user']){ $user = $_POST["user"]; $result = mysql_query("SELECT ..."); if ($myrow = mysql_fetch_array($result)) { do { $xid=$myrow["Xid"]; //this has to be form 2 form2 ===== <form method="post" action="form2.php"> // is this correct - the first form was a "self" printf("<tr><td><input type=\"radio\" name=\"choice\" value=%d><td> <td>%s </td> <td>%s </td> </tr></p></table>", $xid , $myrow["timein"], $myrow["trip"] ); } while ($myrow = mysql_fetch_array($result)); } echo "</select>\n"; } <input type="submit" name="submit-data" value="Submit"> </p> </form> (end of form 2) processing form 2 - but where does it get placed ? ================== if($_POST['submit-data']){ $sscid = $_POST["choice"]; $result11 = mysql_query("SELECT * FROM `Table` WHERE `SSCID` = $sscid "); $myrow11 = mysql_fetch_array($result11); process this data } // does the bracket close here or below with the bracket of form 1 ?> // end processing of both forms. <html> <head> </head> <?php } else { ?> form1 ===== <FORM METHOD=post ACTION="<? echo $PHP_SELF ?>"> <select name="user"><option value="">[Select One] <? $result = mysql_query("SELECT ..."); if ($myrow = mysql_fetch_array($result)) { do { $userid=$myrow["Userid"]; printf("<option value = '$userid'> %s", $myrow["Username"]); } while ($myrow = mysql_fetch_array($result)); echo "</select>\n"; } ?> <input type="submit" name="submit-user" value="Submit"> </p> </form> (end of form 1) <?php } ?> </html> Hi all I have a form that i need to submit a get to the URL and then a second form that sends a different URL parameter but keeps the first in place? Here's my code: Code: [Select] <select name="category" onChange="this.form.submit();"> <option value= >--Choose category--</option> <?php $getcats = mysql_query (" SELECT * FROM `categories` ORDER by name ASC"); while ($showcats = mysql_fetch_array($getcats)) { echo "<option value=\"".$showcats['id']."\"".(($_GET['category']==$showcats['id']) ? ' selected="selected"':'').">".$showcats['name']."</option>"; } ?> </select> </form> <form id="make" name="make" method="GET" action="create-advert.php?category='<?php echo $_GET['category']; ?>"> <select name="make" onchange="this.form.submit();"> <option>--Choose make--</option> <?php $getmakes = mysql_query (" SELECT * FROM `makes` ORDER by name ASC"); while ($showmakes = mysql_fetch_array($getmakes)) { echo "<option value=\"".$showmakes['id']."\"".(($_SESSION['make']==$showmakes['id']) ? ' selected="selected"':'').">".$showmakes['name']."</option>"; } ?> </select> </form> Each time I select the make in the second form the url parameter 'category' disappears from the first? Many thanks Pete [/code] Hello everyone, I'm a newbie with PHP and mySQL and need some assistance with writing a php script that searches a mySQL database using a form. The form has five fields that I want to search from and one is a required field (State). I need to filter or narrow down the search by either two or more fields. The problem I am having is if I used multiple WHERE clauses using the AND condition I have to enter valid information in all five fields and if I use the OR condition then my search does not produce the desired outcome (too many results). I "think" I need to use the AND condition but I need to be able to leave some of the fields blank (except for the State field) and narrow my search with using anywhere from 2-5 search fields. Also, another requirement is to be able to enter partial information in the search field "without" having to enter a wildcard in the search field. Any assistance is very much appreciated and thanks in advance for your help. Form Fields: State SELECT FIELD Lease TEXT FIELD Operator Name TEXT FIELD County or Parish TEXT FIELD Well No TEXT FIELD I have a table called well_permits and it is structure is as follows: date DATE state TEXT county VARCHAR api VARCHAR permit_no VARCHAR operator VARCHAR phone VARCHAR contact VARCHAR lease VARCHAR well_no VARCHAR permit_for VARCHAR welltype VARCHAR wellspot VARCHAR lat FLOAT lon FLOAT depth VARCHAR This is what I have for the connecting to my database and selecting the fields: <?php require_once('../../../Connections/Wldatabase.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; //Variable to store Unique_ID aka API which will be passed to the well-search-results.php page $var_api_rs_search = $_Get['api']; $maxRows_rs_search = 20; $pageNum_rs_search = 0; if (isset($_GET['pageNum_rs_search'])) { $pageNum_rs_search = $_GET['pageNum_rs_search']; } $startRow_rs_search = $pageNum_rs_search * $maxRows_rs_search; $var_state_rs_search = "%"; if (isset($_GET['state'])) { $var_state_rs_search = $_GET['state']; } $var_lease_rs_search = "%"; if (isset($_GET['lease'])) { $var_lease_rs_search = $_GET['lease']; } $var_well_no_rs_search = "%"; if (isset($_GET['well_no'])) { $var_well_no_rs_search = $_GET['well_no']; } $var_operator_rs_search = "%"; if (isset($_GET['operator'])) { $var_operator_rs_search = $_GET['operator']; } $var_county_rs_search = "%"; if (isset($_GET['County'])) { $var_county_rs_search = $_GET['County']; } mysql_select_db($database_Wldatabase, $Wldatabase); $query_rs_search = sprintf("SELECT DISTINCT * FROM well_permits WHERE (well_permits.`state` LIKE %s AND well_permits.county LIKE %s) OR (well_permits.lease LIKE %s) OR (well_permits.operator LIKE %s) OR (well_permits.well_no LIKE %s) ORDER BY well_permits.county", GetSQLValueString($var_state_rs_search, "text"),GetSQLValueString($var_county_rs_search, "text"),GetSQLValueString($var_lease_rs_search, "text"),GetSQLValueString($var_operator_rs_search, "text"),GetSQLValueString($var_well_no_rs_search, "text")); $query_limit_rs_search = sprintf("%s LIMIT %d, %d", $query_rs_search, $startRow_rs_search, $maxRows_rs_search); $rs_search = mysql_query($query_limit_rs_search, $Wldatabase) or die(mysql_error()); $row_rs_search = mysql_fetch_assoc($rs_search); ?> This is my form: <form action="search.php" method="GET" name="frmsearch" target="_self"> <input name="api" type="hidden" value="" /> <div> <table width="900" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td colspan="6"> <p style="text-align:left">Select a State then enter at least one search criteria. State is a required field.</p> * Denotes a required field.<br> </td> </tr> <tr> <td align="right">* State: </td> <td> <select name="state" size="1" dir="ltr" lang="en"> <option value="AL">AL</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="MI">MI</option> <option value="MS">MS</option> <option value="MT">MT</option> <option value="ND">ND</option> <option value="NE">NE</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OS">OS</option> <option value="PA">PA</option> <option value="SD">SD</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="WV">WV</option> <option value="WY">WY</option> </select> </td> <td align="right">County or Parish: </td> <td align="left"><input name="County" type="text" value="" size="35" maxlength="40" /></td> </tr> <tr> <td width="63" align="right">Lease: </td> <td width="239"><input name="lease" type="text" value="" /></td> <td align="right">Well No: </td> <td><input name="well_no" type="text" value="" /></td> </tr> <tr> <td width="111" align="right">Operator Name: </td> <td width="261"><input name="operator" type="text" value="" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td align="left"><input name="search" type="submit" value="Search" /></td> </tr> </table> </form> My Repeat Region starts here <table width="100%" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td align="right"> </td> <th align="center">Operator</th> <th align="center">Lease</th> <th align="center">Well Number</th> <th align="center">County</th> <th align="center">State</th> </tr> <tr> <?php do { ?> <td align="center"><a href="results.php?recordID=<?php echo $row_rs_search['api']; ?>">Select</a></td> <td align="left"><?php echo $row_rs_search['operator']; ?></td> <td align="left"><?php echo $row_rs_search['lease']; ?></td> <td align="center"><?php echo $row_rs_search['well_no']; ?></td> <td align="center"><?php echo $row_rs_search['county']; ?></td> <td align="center"><?php echo $row_rs_search['state']; ?></td> </tr> <?php } while ($row_rs_search = mysql_fetch_assoc($rs_search)); ?> </table> <p align="center">Number of Wells Located: <?php echo ($startRow_rs_search + 1) ?> to <?php echo min($startRow_rs_search + $maxRows_rs_search, $totalRows_rs_search) ?> of <?php echo $totalRows_rs_search ?></p> <table border="0" align="center"> <tr> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, 0, $queryString_rs_search); ?>">First</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, max(0, $pageNum_rs_search - 1), $queryString_rs_search); ?>">Previous</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, min($totalPages_rs_search, $pageNum_rs_search + 1), $queryString_rs_search); ?>">Next</a> <?php } // Show if not last page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, $totalPages_rs_search, $queryString_rs_search); ?>">Last</a> <?php } // Show if not last page ?></td> </tr> </table> Hi all I need to combine URL parameters using the following forms: <form id="type_filter" name="type_filter" method="get" action=""> <label for="type_filter"></label> <select name="type" id="type_filter" style="width: 160px" onchange="this.form.submit();" > <option value="" selected class="meter-calc-text">Product Type</option> <?php $fetchtypes=mysql_query("SELECT * FROM `product_types` ORDER BY id ASC"); while($returnedtypes=mysql_fetch_array($fetchtypes)) { echo "<option value=\"".$returnedtypes['id']."\"".(($returnedtypes['id']==$_GET['type']) ? ' selected="selected"':'')." >".$returnedtypes['name']."</option>"; } ?> </select> </form> <form id="colour_filter" name="colour_filter" method="get" action=""> <label for="colour_filter"></label> <select name="colour" id="colour_filter" style="width: 160px" onchange="this.form.submit();" > <option value="" selected class="meter-calc-text">Colour / Finish</option> <?php $fetchcolours=mysql_query("SELECT * FROM `product_colours` ORDER BY id ASC"); while($returnedcolours=mysql_fetch_array($fetchcolours)) { echo "<option value=\"".$returnedcolours['id']."\"".(($returnedcolours['id']==$_GET['colour']) ? ' selected="selected"':'')." >".$returnedcolours['name']."</option>"; } ?> </select> </form> At the moment they only send one parameter each. How do I drop down on one and add it to the parameter already on there to give this URL: ../stone.php?type=1&colour=1 Many thanks Pete Hi all I am trying to take the data from a form and add into a mySQL table. I have multiple forms on one page that uses a loop: Code: [Select] <?php $textqty = $showbasket['qty']; for ($i = 1; $i <= $textqty ; $i++) { ?> <form id="texts" name="texts" method="post" action=""> <input name="mainqty" type="hidden" value="<?php echo $textqty; ?>" /> <input name="productid" type="hidden" value="<?php echo $showbasket['productid']; ?>" /> <input name="productqtyid" type="hidden" value="<?php echo $i; ?>" /> <input name="productsize" type="hidden" value="<?php echo $showbasket['size']; ?>" /> Text: <input name="text_<?php echo $i; ?>" type="text" value="<?php echo $showtext['text']; ?>" size="35" maxlength="250" /> Colour: <select name="colour"> <?php $getcolours = mysql_query(" SELECT * FROM text_colours ORDER BY id ASC"); while($showcolours = mysql_fetch_array($getcolours)) { ?> <option value="<?php echo $showcolours['colour']; ?>"><?php echo $showcolours['colour']; ?></option> <?php } ?> </select> No. Characters: <br /> <?php } ?> <input name="update" type="submit" id="update" value="Update" /> </form> This data is then inserted into the mySQL: Code: [Select] <?php if(isset($_POST['update'])) { $mqty = $_POST['mainqty']; for ($i = 1; $i <= $mqty ; $i++) { $productid = $_POST['productid']; $productqtyid = $_POST['productqtyid']; $productsize = $_POST['productsize']; $colour = $_POST['colour']; $producttext = $_POST['text_$i']; mysql_query (" INSERT INTO emb_texts SET sessionid = '".$sessionid."', productid = '".$productid."', qtyid = '".$productqtyid."', size = '".$productsize."', colour = '".$colour."', text = '".$producttext."'") or die(mysql_error()); } } ?> This almost works but it adds the $productqtyid the same very time. I'm not sure if I am going about the the right way? Each form needs to add its own values into the mySQL. Many thanks for your help Code: [Select] //display an external link or form button if ($product_link = $meta['mp_product_link']) { $button = '<a class="mp_link_buynow" href="' . esc_url($product_link) . '">' . __('Buy Now »', 'mp') . '</a>'; } else { if ($all_out) { $button .= '<span class="mp_no_stock">' . __('Out of Stock', 'mp') . '</span>'; } else { $button = '<div class="mp_product_variations" name="variation">'; //create select list if more than one variation if (is_array($meta["mp_price"]) && count($meta["mp_price"]) > 1 && empty($meta["mp_file"])) { // for each as foreach ($meta["mp_price"] as $key => &$value) { $disabled = (in_array($key, $no_inventory)) ? ' disabled="disabled"' : ''; $variation_select = '<form name="' . $key . '" class="mp_buy_form" method="post" action="' . mp_cart_link(false, true) . '">\n'; $variation_select .= '<input type="hidden" name="product_id" value="' . $post_id . '" />'; $variation_select .= '<input type="hidden" name="variation" value="' . $key . '">'; $variation_select .= '<span>' . esc_html($meta["mp_var_name"][$key]) . ' - '; if ($meta["mp_is_sale"] && $meta["mp_sale_price"][$key]) { $variation_select .= $mp->format_currency('', $meta["mp_sale_price"][$key]); } else { $variation_select .= $mp->format_currency('', $value); }$variation_select .= "</span>\n"; if ($context == 'list') { if ($variation_select) { $variation_select .= '<a class="mp_link_buynow" href="' . get_permalink($post_id) . '">' . __('Choose Option »', 'mp') . '</a>'; } else if ($settings['list_button_type'] == 'addcart') { $variation_select .= '<input type="hidden" name="action" value="mp-update-cart" />'; $variation_select .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['list_button_type'] == 'buynow') { $variation_select .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } else { $button .= $variation_select; //add quantity field if not downloadable if ($settings['show_quantity'] && empty($meta["mp_file"])) { $button .= '<span class="mp_quantity"><label>' . __('Quantity:', 'mp') . ' <input class="mp_quantity_field" type="text" size="1" name="quantity" value="1" /></label></span> '; } if ($settings['product_button_type'] == 'addcart') { $button .= '<input type="hidden" name="action" value="mp-update-cart" />'; $button .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['product_button_type'] == 'buynow') { $button .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } $variation_select .= "</form>\n"; } //end for each $variation_select .= '</div>'; } else { $button .= '<input type="hidden" name="variation" value="0" />'; } } } Everything inbetween "for each" is being looped, except for the <form>. How can I get it to include <form> and </form> in the loop? Hi Guys, I am attempting to create a program for a local auction house. I arrived at a stand still on a certain issue which is creating a sticky form. On the "enter auction details page" the user will be entering data as the auction is in session. 1. item Description 2. Item Price 3. Bidders Id 4. Qty Of course it would be repetitive to require the user to keep entering the same data for every bidder, so I want to stick the obvious fields which are "item description" & "Item Price" as these don't change until a new item comes up for sale. As of know I am processing the input on a separate page which records all input to the database with a redirect back to the "enter auction details page". I have tried many times to get the item description and item price fields to stick. These would need to change as the user moves onto the next item in which the description and price would change as well. Here is my current code for this part: Code: [Select] <?php session_start(); $field_itemDescription = ""; //iyem description, default as blank if (isset($_SESSION['itemDescription'])) $itemDescription = $_SESSION['itemDescription']; ?> <form action="record_trans.php" method="post"> <font face= "calibri" size= "4"> <table> <tr> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value="<?php echo $itemDescription;?>"></td> </tr> <tr> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value="<?php echo $itemPrice;?>"> </td> </tr> </tr> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "bidderId" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <center><input type="submit" name="submit" value= "Save & Cont." " /></center> </form></font> |