scmeeker Posted March 21, 2011 Share Posted March 21, 2011 The information is drawn in from a table into a form that the user will click submit and all the rows will be inputted into the table with their username association. With this form, its only inputting the last row and not all of them. You're help is much appreciated! Here is the form in the PHP area: while($row=mysql_fetch_array($get_items_sql)){ $name =$row['item']; $date = ($row['expiration_date']); $exp_date = date('M d Y', strtotime($row['expiration_date'])); $content .= ""; $content .="<table width=\"450\" border=\"0\"><tr><td width=\"200\"><span class=\"anotherfont\"><input name=\"item[]\" type=\"hidden\" value=\"$name\" id=\"item[]\">$name</span></td><td width=\"200\"><span class=\"greenfont\"><input name=\"expiration_date[]\" type=\"hidden\" value=\"$date\" id=\"expiration_date[]\">$exp_date</span><input name=\"username[]\" type=\"hidden\" value=\"$username\" id=\"username[]\"/> </td></tr><br /></table>"; $content .= "\n"; } $content .= "</ul>\n"; Then below is part of the HTML Form with $content referenced: <form action="add_select.php?source_id=<?php echo $coupon_source ?>" method="post" enctype="multipart/form-data" name="add_new" id="add_new"> <?php echo $content ?> <input name="SUBMIT" type="submit" value="submit" /></form><br /> Then here is the section from the "add_select.php" file from the form: include('connect.php'); foreach($_POST['item'] as $row=>$item) { $Item_name=$item; $expiration_date=$_POST['expiration_date'][$row]; $username=$_POST['username'][$row]; } foreach($_POST['item'] as $row=>$item) { $Item_name=mysql_real_escape_string($item); $expiration_date=mysql_real_escape_string($_POST['expiration_date'][$row]); $username=mysql_real_escape_string($_POST['username'][$row]); } $sql2="INSERT INTO place (item, expiration_date, username) VALUES ('$Item_name', '$expiration_date', '$username')"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }else { header("location:insert_complete.php"); } Quote Link to comment Share on other sites More sharing options...
scmeeker Posted March 22, 2011 Author Share Posted March 22, 2011 What I'm really trying to figure out is how I get this to loop around and add all the selected entries instead of only the last one. Thanks! Quote Link to comment Share on other sites More sharing options...
scmeeker Posted March 22, 2011 Author Share Posted March 22, 2011 I'm still stumped on this one and would really appreciate the help. I'm still researching but without any luck. Thanks! Quote Link to comment Share on other sites More sharing options...
jcbones Posted March 25, 2011 Share Posted March 25, 2011 This post is going to assume that you are receiving the data that you expect. Try running this in your add_select.php include('connect.php'); foreach($_POST['item'] as $row=>$item) { $Item_name=mysql_real_escape_string($item); $expiration_date=mysql_real_escape_string($_POST['expiration_date'][$row]); $username=mysql_real_escape_string($_POST['username'][$row]); $query_row[] = "('$item_name','$expiration_date','$username')"; } $sql2="INSERT INTO place (item, expiration_date, username) VALUES " . implode(',',$query_row); if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }else { header("location:insert_complete.php"); } Quote Link to comment Share on other sites More sharing options...
scmeeker Posted March 25, 2011 Author Share Posted March 25, 2011 That did it! Thank you SO much! I appreciate your feedback. Quote Link to comment 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.