Peterod Posted September 26, 2010 Share Posted September 26, 2010 I've read the php manual and a good few posts with similar but not identical problems and I am struggling to understand how to do this. Ive tailored my test site to help describe the problems that I have. www.peterod.co.uk the form is the first link in the left hand bar. Here is the code that creates the form. <?php // make connection require_once "../classes/sqlconselfbuild.php"; $query = mysql_query("SELECT * FROM `materials` ORDER BY `id` ASC"); ?> <form action="../engines/testengine1.php" method="post"> <?php // results while ($row = mysql_fetch_array($query)): $id = $row['id']; ?> <p> id number: <input type="text" name="materials[<?php echo $id; ?>][name]" value="<?php echo $row['id']; ?>" /> Material: <input type="text" name="materials[<?php echo $id; ?>][material]" value="<?php echo $row['material']; ?>" /> Stage: <input type="text" name="materials[<?php echo $id; ?>] [stage]" value="<?php echo $row['stage']; ?>" /> Qantity: <input type="text" name="materials[<?php echo $id; ?>][quantity]" value="<?php echo $row['quantity']; ?>" /> Unit: <input type="text" name="materials[<?php echo $id; ?>][unit]" value="<?php echo $row['unit']; ?>" /> <br /> </p> <?php endwhile; ?> <input type="submit" name="submit" value="Submit" /> </form> I am unsure how to get this information to insert into the database. How do you use the UPDATE query with a loop generated form ? Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/ Share on other sites More sharing options...
Peterod Posted September 26, 2010 Author Share Posted September 26, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116059 Share on other sites More sharing options...
litebearer Posted September 26, 2010 Share Posted September 26, 2010 please show the code for testengine1.php Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116083 Share on other sites More sharing options...
sasa Posted September 27, 2010 Share Posted September 27, 2010 <?php foreach ($_POST['materials'] as $mater){ $name = $mater['name']; //or is it $id $material = $mater['material']; $stage = $mater['stage']; //and so on // satanize inputs mysql_query("UPDATE table_name SET material='$material', stage='stage' etc. WHERE id='$name'"); } ?> and add disabled="disabled" atribute to your input tag for id_number Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116141 Share on other sites More sharing options...
Peterod Posted September 27, 2010 Author Share Posted September 27, 2010 heres the engine, as based on above. I only have a little spare time at night due to new baby so I dont get long to mess around with the site, so basically any help you guys give is 100% appreciated. <?php // make conn require_once "../classes/sqlconselfbuild.php"; foreach ($_POST['materials'] as $mater){ $name = $mater['name']; //or is it $id (not sure... anyone more help) $material = $mater['material']; $stage = $mater['stage']; $unit = $mater ['unit']; // satanize inputs mysql_query("UPDATE materials SET material='$material', stage='stage', quantity='quantity',unit='unit' WHERE id='$name'"); } ?> its live at the above address. I get a blank screen at the moment I think there are a few things wrong. please help update heres how i have it at the moment but still not working <?php // make conn $conn = require_once "../classes/sqlconselfbuild.php"; foreach ($_POST['materials'] as $mater){ $name = $mater['name']; //or is it $id (not sure... anyone more help) $material = $mater['material']; $stage = $mater['stage']; $unit = $mater ['unit']; // satanize inputs $sql = mysql_query("UPDATE materials SET material='$material', stage='stage', quantity='quantity',unit='unit' WHERE id='$name'"); } mysql_select_db('peterodc_selfbuild'); $retval = mysql_query( $sql,$conn); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; mysql_close($conn); } else { ?> Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116506 Share on other sites More sharing options...
sasa Posted September 28, 2010 Share Posted September 28, 2010 try <?php mysql_connect('localhost', 'username', 'password'); //change to your username and password mysql_select_db('peterodc_selfbuild'); foreach ($_POST['materials'] as $mater){ $name = $mater['name']; //or is it $id (not sure... anyone more help) $material = $mater['material']; $stage = $mater['stage']; $unit = $mater ['unit']; // satanize inputs $sql = mysql_query("UPDATE materials SET material='$material', stage='$stage', quantity='$quantity',unit='$unit' WHERE id='$name'"); } ?> Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116633 Share on other sites More sharing options...
Pikachu2000 Posted September 28, 2010 Share Posted September 28, 2010 // satanize inputs Yes, definitely satanize your inputs. Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116635 Share on other sites More sharing options...
Peterod Posted September 28, 2010 Author Share Posted September 28, 2010 thanks sasa that's working now This is a work in progress whilst I am getting my head around php. I have more to add to the form but that will get me started on the principles of it all. Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1116805 Share on other sites More sharing options...
Peterod Posted October 3, 2010 Author Share Posted October 3, 2010 I thought this was working but now i get an invalid augment. when i hit submit i nothing appeared to happen, the page returned was black so i did view source and there was the error. Could someone please double check the above code as I cant see whats wrong. Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1118705 Share on other sites More sharing options...
jcbones Posted October 4, 2010 Share Posted October 4, 2010 invalid argument on what? Need more details. Link to comment https://forums.phpfreaks.com/topic/214468-help-with-form-processing-from-loop/#findComment-1118757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.