KeeganWolf Posted May 27, 2009 Share Posted May 27, 2009 I'm trying to create a loop that will list all the information within a part of a mysql table, while including a form that will allow them to change the value in a field. I'm not sure about how to post this information after the user has entered the changes. Here's what I have so far. <?php // Make a MySQL Connection include_once "../scripts/connect_to_mysql.php"; // Create a page with the specified table info $store = "4071"; $local = "WF"; $query = "SELECT * FROM Inventory$store WHERE local='$local'"; $result = mysql_query($query) or die(mysql_error()); echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Product ID</th>"; echo "<th>Description</th>"; echo "<th>Quantity</th>"; echo "<th>Case</th>"; echo "<th>case</th></tr>"; while($row = mysql_fetch_array($result)){ extract($row); echo "<tr><td>"; echo $row['fomez']; echo "</td><td>"; echo $row['desc']; echo "</td><td>"; echo $row['quant']; echo "</td><td>"; echo $row['case']; echo "</td><td>"; echo "<input type='text' method='post' value='$case'></form>\n"; //echo ""; echo "</td></tr>"; } echo "</table>"; echo "<input type='submit' value='Continue to the next step.'></form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/159883-create-page-in-loop-and-allow-users-to-change-information/ Share on other sites More sharing options...
Alt_F4 Posted May 28, 2009 Share Posted May 28, 2009 Hi there, A couple of things: It could just be me but i cant see where you use the opening <form> tag also you seem to be closing the form twice here.. echo "<input type='text' method='post' value='$case'></form>\n"; and here.. echo "<input type='submit' value='Continue to the next step.'></form>\n"; I'm not sure that you need the extract function here either?? I haven't seen it used though, so i could be wrong. extract($row); in order to be able to post this information you will need something like the following: //set action to the name of the page you wish to send the form information to echo '<form action="update.php" method="post">'; echo '<table border="1" align="center">'; echo '<tr>'; echo '<th>Product ID</th>'; echo '<th>Description</th>'; echo '<th>Quantity</th>'; echo '<th>Case</th>'; echo '<th>case</th>'; echo '</tr>'; $i=0; //declare a variable to increment each time we start a new row while($row = mysql_fetch_array($result)){ echo '<tr>'; echo '<td>'.$row['fomez'].'</td>'; echo '<td>'.$row['desc'].'</td>'; echo '<td>'.$row['quant'].'</td>'; echo '<td>'.$row['case'].'</td>'; //use the increment variable ($i) to name the input field so we can iterate throught the fields later to get the data echo '<td><input type="text" name="case_'.$i.'" value="'.$case.'"></td>'; echo '</tr>'; $i++; //increment the variable } echo '<td><input type="hidden" name="num_articles" value="'.$i.'"></td>'; echo '</table>'; echo '<input type="submit" value="Continue to the next step."></form>'; then in the page that will receive the form information, something along these lines: for($i=0;$i<$_POST['num_articles'];i++) { //loop through each variable and extract the data $data = $_POST['case'.$i]; //append the data to a query string, array or do with it what you will } btw this code has not been tested, but it should work ok Link to comment https://forums.phpfreaks.com/topic/159883-create-page-in-loop-and-allow-users-to-change-information/#findComment-843884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.