Jump to content

Recommended Posts

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.