tjverge Posted February 8, 2011 Share Posted February 8, 2011 I'm back, I have a code that based on my understanding should work, but needless to say doesn't <?php $sql ="select * from `piprice`"; $result = mysql_query($sql); $count = mysql_num_rows($result); echo "<table border=1><tr><td>Product Name</td><td>Item ID</td><td>Price</td><td>Enabled</td>"; echo "<form action=main.php?id=test1.php method=post>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['product name']."</td>"; echo "<td>".$id[] = $row['item id'];$row['item id']."</td>"; echo "<td>".$row['price']."</td>"; $enabled[] = $row['enabled']; echo"<td><select name=".$enabled.">< <option Value=".$row['enabled'].">".$row['enabled']."</option> <option Value=Yes>Yes</option> <option Value=No>No</option> /select></td</tr>"; } echo "<input name=submit type=submit value=Update>"; echo "</form></table>"; if(isset($_POST['submit'])) { for($i=0;$i<$count;$i++){ $sql1="UPDATE `piprice` SET `enabled` = '$enabled[$i]' WHERE `item id` ='$id[$i]'"; $result1=mysql_query($sql1) or die (mysql_error()); } } ?> Basically I want to be able to pick yes/no and have it update in the database. One a side note is there a good site for me to learn php on (I just know the basics) besides asking 101 questions here Quote Link to comment https://forums.phpfreaks.com/topic/227081-updating-more-then-one-row/ Share on other sites More sharing options...
QuickOldCar Posted February 8, 2011 Share Posted February 8, 2011 Is this the complete code? I don't see anywhere that you connected to the database. http://www.w3schools.com/php/php_mysql_connect.asp Quote Link to comment https://forums.phpfreaks.com/topic/227081-updating-more-then-one-row/#findComment-1171502 Share on other sites More sharing options...
tjverge Posted February 8, 2011 Author Share Posted February 8, 2011 it's the complete code for this page, it's run inside another page that connects to the DB Quote Link to comment https://forums.phpfreaks.com/topic/227081-updating-more-then-one-row/#findComment-1171503 Share on other sites More sharing options...
tjverge Posted February 8, 2011 Author Share Posted February 8, 2011 Ok I think the problem is here $enabled[] = $row['enabled']; echo"<td><select name=".$enabled.">< <option Value=".$row['enabled'].">".$row['enabled']."</option> <option Value=Yes>Yes</option> <option Value=No>No</option> /select> I need to give it a name so I can pull the post date, the only problem is I'm unsure how to do that where it in a loop Quote Link to comment https://forums.phpfreaks.com/topic/227081-updating-more-then-one-row/#findComment-1171548 Share on other sites More sharing options...
tjverge Posted February 8, 2011 Author Share Posted February 8, 2011 Problem solved, code posted below for anyone else who is having this kind of problem. <?php $sql ="select * from `piprice`"; $result = mysql_query($sql); $count = mysql_num_rows($result); echo "<table border=1><tr><td>Product Name</td><td>Item ID</td><td>Price</td><td>Enabled</td>"; echo "<form action=main.php?id=test1.php method=post>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['product name']."</td>"; echo "<td>".$id[] = $row['item id'];$row['item id']."</td>"; echo "<td>".number_format($row['price'],2)."</td>"; echo"<td><select name = ename[]> <option Value=".$row['enabled'].">".$row['enabled']."</option> <option Value=Yes>Yes</option> <option Value=No>No</option> /select></td</tr>"; } echo "<input name=submit type=submit value=Update>"; echo "</form></table>"; if(isset($_POST['submit'])) { $ename = $_POST['ename']; for($i=0;$i<$count;$i++){ echo $name; $sql1="UPDATE `piprice` SET `enabled` = '$ename[$i]' WHERE `item id` ='$id[$i]'"; $result1=mysql_query($sql1) or die (mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/227081-updating-more-then-one-row/#findComment-1171565 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.