essjay_d12 Posted April 21, 2008 Share Posted April 21, 2008 Hi my code was working. Then when adding a second row into the database it only seems to picking up the $_POST['tree'.$id] value <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="updateTrees.php" method="post"> <table> <?php echo '<tr><td>Tree</td><td>Type</td><td>pl</td><td>1 lit</td><td>2 lit</td><td>3 lit</td><td>5 lit</td><td>7 lit</td><td>10 lit</td><td>15 lit</td><td>Groups</td><td>Leaves</td><td>Hardiness</td><td>Text</td><td>Description</td><td>Price</td></tr>'; $conn = mysql_connect("localhost", "admin", "adm1n"); mysql_select_db("wizotrees",$conn); $query = "SELECT id, tree, type, pl, 1lit, 2lit, 3lit, 5lit, 7lit, 10lit, 15lit, groups, leaves, hardiness, text, description, price FROM trees"; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_num_rows($result); $i=1; echo $rows; if ($rows > 0) { while ($row = mysql_fetch_assoc($result)) { echo '<tr><td><input name="tree'; echo $i; echo '" type="text" value="'; echo ($row['tree']); echo '" /></td><td><input name="type'; echo $i; echo '" type="text" value="'; echo ($row['type']); echo '" /></td><td><input name="pl'; echo $i; echo '" type="text" size="3" value="'; echo ($row['pl']); echo '" /></td><td><input name="1lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['1lit']); echo '" /></td><td><input name="2lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['2lit']); echo '" /></td><td><input name="3lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['3lit']); echo '" /></td><td><input name="5lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['5lit']); echo '" /></td><td><input name="7lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['7lit']); echo '" /></td><td><input name="10lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['10lit']); echo '" /></td><td><input name="15lit'; echo $i; echo '" type="text" size="3" value="'; echo ($row['15lit']); echo '" /></td><td><input name="groups'; echo $i; echo '" type="text" value="'; echo ($row['groups']); echo '" /></td><td><input name="leaves'; echo $i; echo '" type="text" value="'; echo ($row['leaves']); echo '" /></td><td><input name="hardiness'; echo $i; echo '" type="text" size="3" value="'; echo ($row['hardiness']); echo '" /></td><td><input name="text'; echo $i; echo '" type="text" value="'; echo ($row['text']); echo '" /></td><td><input name="description'; echo $i; echo '" type="text" value="'; echo ($row['description']); echo '" /></td><td><input name="price'; echo $i; echo '" type="text" size="5" value="'; echo ($row['price']); echo '" /></td><td><input name="idCheck'; echo $i; echo '" type="hidden" value="'; echo ($row['id']); echo '" /></td></tr>'; $i++; } } else { echo "<tr><td>There are no items</td></tr>"; } echo '<input name="rowCount" type="hidden" value="'; echo $rows; echo '" /><tr><td><input type="submit" name="submit" value="Update" /></td></tr>'; ?> </table></form> </body> </html> and then the form it goes to is ... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php $conn = mysql_connect("localhost", "admin", "adm1n"); mysql_select_db("wizotrees",$conn); $rowCount = $_POST['rowCount']; $insertCmd = NULL; for($i=1; $i<=$rowCount; $i++) { $id = $_POST['idCheck.$i']; $tree = $_POST['tree'.$i]; $type = $_POST['type'.$id]; $pl = $_POST['pl'.$id]; $_1lit = $_POST['1lit'.$id]; $_2lit = $_POST['2lit'.$id]; $_3lit = $_POST['3lit'.$id]; $_5lit = $_POST['5lit'.$id]; $_7lit = $_POST['7lit'.$id]; $_10lit = $_POST['10lit'.$id]; $_15lit = $_POST['15lit'.$id]; $groups = $_POST['groups'.$id]; $leaves = $_POST['leaves'.$id]; $hardiness = $_POST['hardiness'.$id]; $text = $_POST['text'.$id]; $description = $_POST['description'.$id]; $price = $_POST['price'.$id]; echo $id; echo $tree; echo $type; $insertCmd = $insertCmd.'('.$id.", '".$tree."', '".$type."', ".$pl.", ".$_1lit.", ".$_2lit.", ".$_3lit.", ".$_5lit.", ".$_7lit.", ".$_10lit.", ".$_15lit.", '".$groups."', '".$leaves."', ".$hardiness.", '".$text."', '".$description."', ".$price; IF ($rowCount>1) { $insertCmd = $insertCmd."), "; } else { $insertCmd = $insertCmd.")"; } } echo $insertCmd; ?> </body> </html> anybody see why it would have suddenly changed? regards, s Quote Link to comment Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 Are you editing every row in your table?? Ray Quote Link to comment Share on other sites More sharing options...
essjay_d12 Posted April 21, 2008 Author Share Posted April 21, 2008 yeah i sorted it apologies Quote Link to comment Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 So you are all set?? If so please mark thread as solved. Thanks Ray 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.