perky416 Posted April 9, 2011 Share Posted April 9, 2011 Hi Guys, I am trying update some array values in my database. For some reason using the code below the $checked and $counter values are not working. I have added the echos for debugging purposes and nothing is being echoed. $query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer'"); while ($row = mysql_fetch_assoc($query)) { $checked = $_POST['checkbox'][$y]; $counter = $_POST['counter'][$y]; echo $checked; echo $counter; $date = date("Y-m-d"); $time = date("H:i:s"); mysql_query("UPDATE offers SET offer='$counter',seller_status='Counter Offer Made',buyer_status='Counter Offer Received',date='$date',time='$time',seller_action='0',buyer_action='1' WHERE domain='$checked'"); } When i do the following it echos the $checked and $counter values perfectly so i know that the form is posting ok. foreach ($_POST['checkbox'] as $checked) { echo $checked; } foreach ($_POST['counter'] as $counter) { echo $counter; } Can anybody figure out what is wrong with my while loop? Iv been at it for ages and cant seem to crack it. Thanks Link to comment https://forums.phpfreaks.com/topic/233212-problem-with-while-loop/ Share on other sites More sharing options...
Jnerocorp Posted April 9, 2011 Share Posted April 9, 2011 what is "$y" in $checked = $_POST['checkbox'][$y]; Link to comment https://forums.phpfreaks.com/topic/233212-problem-with-while-loop/#findComment-1199340 Share on other sites More sharing options...
perky416 Posted April 9, 2011 Author Share Posted April 9, 2011 Hi the [$y] is for the array for the form field name <input type='hidden' name='checkbox[$y]' />. Iv just managed to figure out what i was doing wrong. I missed out the $y = 0; before the loop and $y++; in the loop. Using the following makes it work correctly: $query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer'"); $y=0; while ($row = mysql_fetch_assoc($query)) { $checked = $_POST['checkbox'][$y]; $counter = $_POST['counter'][$y]; echo $checked; echo $counter; $date = date("Y-m-d"); $time = date("H:i:s"); mysql_query("UPDATE offers SET offer='$counter',seller_status='Counter Offer Made',buyer_status='Counter Offer Received',date='$date',time='$time',seller_action='0',buyer_action='1' WHERE domain='$checked'"); $y++; } Done it again, been trying to figure it out for hours and as soon as I post on here i manage to figure it out lol. Thats about the 3rd time iv done it. Thanks anyway. Link to comment https://forums.phpfreaks.com/topic/233212-problem-with-while-loop/#findComment-1199346 Share on other sites More sharing options...
Jnerocorp Posted April 9, 2011 Share Posted April 9, 2011 glad you found the issue Link to comment https://forums.phpfreaks.com/topic/233212-problem-with-while-loop/#findComment-1199357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.