Orionsbelter Posted December 17, 2013 Share Posted December 17, 2013 How would I submit the below info? <?php include "common/db_connect.php"; $date = date("Y-m-d"); if($_POST['button']){ } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Funky Chalk</title> <link rel="stylesheet" href="css/960.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="css/template.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="css/colour.css" type="text/css" media="screen" charset="utf-8" /> </head> <body> <div id="container"> <?php include("nav-bar.php"); ?> <div id="content" class="container_16 clearfix"> <table width="90%" border="1"> <tr> <td width="71%"><strong>Order</strong></td> <td width="22%"><strong>Service</strong></td> <td width="7%"><strong>Weight</strong></td> </tr> <?php $query=mysql_query("SELECT * FROM `delivery_information` WHERE `date`='$date'"); while($fetch_DI=mysql_fetch_object($query)){ $fetchDPD=mysql_fetch_object(mysql_query("SELECT * FROM `DPD` WHERE `ref`='$fetch_DI->customer_ref'")); echo" <tr> <td> "; $string=mysql_query("SELECT * FROM `delivery_items` WHERE `customer_ref`='$fetch_DI->customer_ref'"); while($fetch_items=mysql_fetch_object($string)){ echo"<span class='paraProducts'>".$fetch_items->item."</span><br>"; } echo"<span class='paraDetails'><font color='#0099CC'>".$fetch_DI->contact_name."</font> Order ID: <font color='#0099CC'>".$fetch_DI->customer_ref."</font></span>"; echo"</td>"; echo"<td valign='top'><select name='service_".$fetchDPD->ref."' id='select'>"; echo"<option value='12'"; if($fetchDPD->service=="12"){echo'selected="selected"';} echo">Next Day</option>"; echo"<option value='11'"; if($fetchDPD->service=="11"){echo'selected="selected"';} echo">Two Day</option>"; echo"<option value='59'"; if($fetchDPD->service=="59"){echo'selected="selected"';} echo">Hermes</option>"; echo"<option value='19'"; if($fetchDPD->service=="19"){echo'selected="selected"';} echo">Classic</option>"; echo"<option value='10'"; if($fetchDPD->service=="10"){echo'selected="selected"';} echo">Express Air</option>"; echo"</select> to ".$fetch_DI->country_code." (".$fetch_DI->post_code.")</td>"; echo'<td><input name="weight_'.$fetchDPD->ref.'" type="text" id="textfield" size="2" /> KG</td> </tr>'; } ?> <tr> <td colspan="3"><div align="right"> <input type="button" name="button" id="button" value="Submit" style="margin:3px;" /> </div></td> </tr> </table> <p> </p> <p> </p> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/ Share on other sites More sharing options...
Ch0cu3r Posted December 17, 2013 Share Posted December 17, 2013 (edited) By wrapping your input fields within <form></form> tags <form action="file/to/process/form.php" method="post"> // your form fields here </form> Edited December 17, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462580 Share on other sites More sharing options...
Orionsbelter Posted December 17, 2013 Author Share Posted December 17, 2013 Yeah the page isn't finished it seems to have missed off my text after I pasted the code basically how would I define the text field and select to update the MySQL database as these are automatically generated I.E the name Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462585 Share on other sites More sharing options...
Orionsbelter Posted December 17, 2013 Author Share Posted December 17, 2013 This page is too populate a table of orders that is going out for delivery it then needs to allow a user to select a service and add the weight. As there will be no idea how many rows will be present nor the names of the input how can I declare the inputs so I can successfully update the records with the selected service and weights. Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462586 Share on other sites More sharing options...
Solution objnoob Posted December 18, 2013 Solution Share Posted December 18, 2013 You append [] to the input element's names making the value an array of values. <?php # on form create while( $row = msyqli_fetch() ) { # 1 or more expression not complete. echo '<input type="checkbox" name="id[' . $row['id'] . ']" value="1" /> input type="text" name='weight[' . $row['id'] . ']' value /> <br />'; } ?> <!-- creates something like this --> <input type="checkbox" name="id[MYSQL_RECORD_ID_HERE]" value="1" /> input type="text" name='weight[MYSQL_RECORD_ID_HERE]' value /> <br /> <input type="checkbox" name="id[NEXT_RECORD_ID_HERE]" value="1" /><input type="text" name='weight[NEXT_RECORD_ID_HERE]' value /> <br /> <input type="checkbox" name="id[LAST_RECORD_ID_HERE]" value="1" /><input type="text" name='weight[LAST_RECORD_ID_HERE]' value /> <?php # on postback foreach($_POST['id'] as $record_id => $nothing_useful){ $sql = "update tOrders set weight=" . (float)$_POST['weight'][$record_id] . "where order_id =".(int)$record_id; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462600 Share on other sites More sharing options...
Orionsbelter Posted December 18, 2013 Author Share Posted December 18, 2013 (edited) Thank you for your response, I have edited the code and getting an error for the foreach loop; Where have I gone wrong? <?php include "common/db_connect.php"; $date = date("Y-m-d"); if($_POST['submit']){ foreach($_POST['id'] as $record_id => $nothing_useful){ mysql_query("UPDATE `DPD` SET `weight` ='".$_POST['weight'][$record_id]."', `service`='".$_POST['service'][$record_id]."' WHERE `ref` ='".$record_id."'"); } echo"Submitted"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Funky Chalk</title> <link rel="stylesheet" href="css/960.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="css/template.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="css/colour.css" type="text/css" media="screen" charset="utf-8" /> </head> <body> <div id="container"> <?php include("nav-bar.php"); ?> <div id="content" class="container_16 clearfix"> <form id="form1" method="post" action=""> <table width="90%" border="1"> <tr> <td><div align="center"><strong> </strong></div></td> <td><strong>Order</strong></td> <td><strong>Service</strong></td> <td><strong>Weight</strong></td> </tr> <?php $query=mysql_query("SELECT * FROM `delivery_information` WHERE `date`='$date'"); while($fetch_DI=mysql_fetch_object($query)){ $fetchDPD=mysql_fetch_object(mysql_query("SELECT * FROM `DPD` WHERE `ref`='$fetch_DI->customer_ref'")); echo' <tr> <td><input name="id['.$fetchDPD->ref.']" type="checkbox" id="checkbox" checked="checked" /></td> <td> '; $string=mysql_query("SELECT * FROM `delivery_items` WHERE `customer_ref`='$fetch_DI->customer_ref'"); while($fetch_items=mysql_fetch_object($string)){ echo"<span class='paraProducts'>".$fetch_items->item."</span><br>"; } echo"<span class='paraDetails'><font color='#0099CC'>".$fetch_DI->contact_name."</font> Order ID: <font color='#0099CC'>".$fetch_DI->customer_ref."</font></span>"; echo"</td>"; echo'<td valign="top"><select name="service['.$fetchDPD->ref.']" id="select">'; echo"<option value='12'"; if($fetchDPD->service=="12"){echo'selected="selected"';} echo">Next Day</option>"; echo"<option value='11'"; if($fetchDPD->service=="11"){echo'selected="selected"';} echo">Two Day</option>"; echo"<option value='59'"; if($fetchDPD->service=="59"){echo'selected="selected"';} echo">Hermes</option>"; echo"<option value='19'"; if($fetchDPD->service=="19"){echo'selected="selected"';} echo">Classic</option>"; echo"<option value='10'"; if($fetchDPD->service=="10"){echo'selected="selected"';} echo">Express Air</option>"; echo"</select> to ".$fetch_DI->country_code." (".$fetch_DI->post_code.")</td>"; echo'<td><input name="weight['.$fetchDPD->ref.']" type="text" id="textfield" size="2" /> KG</td> </tr>'; } ?> <tr> <td colspan="4"><div align="right"> <input type="submit" name="submit" id="submit" value="Submit" /> </div></td> </tr> </table> <p> </p> <p> </p> </form> <p> </p> <p> </p> </div> </div> </body> </html> Edited December 18, 2013 by blmg911 Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462623 Share on other sites More sharing options...
Orionsbelter Posted December 18, 2013 Author Share Posted December 18, 2013 fixed this now, it was an issue with naming the input for check box. Thank you for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/284821-php-forms-generated-from-mysql-and-submit/#findComment-1462624 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.