dvdriper Posted January 9, 2008 Share Posted January 9, 2008 hi, I have a problem, look at this: ------code------- <form action='take_validation.php' method='post'> <?php do { ... printf ("<input type='checkbox' value='%s' name='valid_photo'>", $row["id"]); }while($row = mysql_fetch_array($result)); ?> ... </form> ------code------- the take_validation.php code: ------code------- $valid_photo = $_POST["valid_photo"]; $result = mysql_query("SELECT * FROM validating_photos WHERE id='$valid_photo'"); $row = mysql_fetch_array($result); $date = date("Y-m-d"); $i = $row["name"]; $t = $row["thread"]; if (file_exists("../image_storage/$t/$i")) { $random_nr = rand(); $i = "$random_nr".$i; } rename("validating_photos/$row[name]", "../image_storage/$row[thread]/$i"); mysql_query("INSERT INTO photos (name, whom, added, added_by) VALUES ('$i', '$row[thread]', '$date', '$row[who]')") or die(mysql_error()); ------code------- this works correct, -> when I check a checkbox and submit the form I get the result that I need, but, when I check more than one checkbox, I obtain the result only for the last... this is how it need to be, bu I need when I check multimple checkboxes, the multimple checkboxes to be validated, I tryed to do this: ------code------- for ($i = 1; $i <= 100; $i++) { $valid_photo.$i = $_POST["valid_photo".$i]; } ------code------- and it didn't worked please someone, maybe tryed, this, please tell me how to do this I know it's simple for advanced programmers, i'm still a beginer, maybe I explained not so good... sorry for my bad english Link to comment https://forums.phpfreaks.com/topic/85200-a-loop-for-db-checkboxes-please-help/ Share on other sites More sharing options...
nikefido Posted January 9, 2008 Share Posted January 9, 2008 Please use [ php] and [ code] tags (without the extra space there) hi, I have a problem, look at this: <form action='take_validation.php' method='post'> <?php do { ... printf ("<input type='checkbox' value='%s' name='valid_photo'>", $row["id"]); }while($row = mysql_fetch_array($result)); ?> ... </form> the take_validation.php code: $valid_photo = $_POST["valid_photo"]; $result = mysql_query("SELECT * FROM validating_photos WHERE id='$valid_photo'"); $row = mysql_fetch_array($result); $date = date("Y-m-d"); $i = $row["name"]; $t = $row["thread"]; if (file_exists("../image_storage/$t/$i")) { $random_nr = rand(); $i = "$random_nr".$i; } rename("validating_photos/$row[name]", "../image_storage/$row[thread]/$i"); mysql_query("INSERT INTO photos (name, whom, added, added_by) VALUES ('$i', '$row[thread]', '$date', '$row[who]')") or die(mysql_error()); this works correct, -> when I check a checkbox and submit the form I get the result that I need, but, when I check more than one checkbox, I obtain the result only for the last... this is how it need to be, bu I need when I check multimple checkboxes, the multimple checkboxes to be validated, I tryed to do this: for ($i = 1; $i <= 100; $i++) { $valid_photo.$i = $_POST["valid_photo".$i]; } and it didn't worked please someone, maybe tryed, this, please tell me how to do this I know it's simple for advanced programmers, i'm still a beginer, maybe I explained not so good... sorry for my bad english Now, the standard method I've seen for looping through result sets is to use a WHILE loop (but since yours works, that's OK) example: while($row = mysql_fetch_array($result) { printf ("<input type='checkbox' value='%s' name='valid_photo'>", $row["id"]); } You can use whichever way you like most, of course. Now "$valid_photo.$i = $_POST["valid_photo".$i];" i believe is your problem - the .$i is not set as a $_POST variable, and so PHP will create an error (i believe). I'm also confused by the syntax of .$i - i have not come across this in my php experience (not to say that I have a ton of it) - what are you trying to do there? If you are trying to concatenate - I don't think you can use POST variables in that manner Link to comment https://forums.phpfreaks.com/topic/85200-a-loop-for-db-checkboxes-please-help/#findComment-434683 Share on other sites More sharing options...
dvdriper Posted January 9, 2008 Author Share Posted January 9, 2008 I want to insert multimple results of checkboxes in the DB, in the example above, the code inserts only one , I need somehow, to modify the code, that it'll work for more chekboxes, not only for one understand what I mean? Link to comment https://forums.phpfreaks.com/topic/85200-a-loop-for-db-checkboxes-please-help/#findComment-434716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.