Hi there
I have a huge difficulties with php checkbox inside do while loop.

    <?php do { ?>
<p>
</p>


<div id="nazwa_firmy">
        <form name="szczegoly_firmy" method="post" action="szczegoly.php">

    <?php echo $row_wybieranie_firm['nazwa'];?>

        <input type="submit" name="firma_szczegoly" id="firma_szczegoly" value="Szczegóły" tabindex="1"> 

        <input type="hidden" name="id_firmy" id="id_firmy" value="<?php echo $row_wybieranie_firm['id']?>">     

        </form>
</div>

<div id="adres_www">
      <a href="http://<?php echo $row_wybieranie_firm['www']; ?>"><?php echo $row_wybieranie_firm['www']; ?></a>
    </div>
    <form name="kopiowanie_email" method="post" action="email.php">  
      <div id="adres_email">
       <a href="mailto:<?php echo $row_wybieranie_firm['email']; ?>"><?php echo $row_wybieranie_firm['email']; ?></a>
        <input type="checkbox" name="zaznaczenie_email[]" id="zaznaczenie_email[]" tabindex="2" value="<?php echo $row_wybieranie_firm['email']; ?>"><label for="zaznaczenie_email"></label>
      </div>
      <div id="szczegoly">
<?php echo $row_wybieranie_firm['skrot'] . "."; 
?>


<?php echo $row_wybieranie_firm['ulica']. " "; 
?>

<?php if ($row_wybieranie_firm['dodatkowa_litera'] == ""){ 
        echo $row_wybieranie_firm['nr_domu'] . "," ;}
        else{
        echo $row_wybieranie_firm['nr_domu'];}
?>
<?php if ($row_wybieranie_firm['dodatkowa_litera'] != ""){
          echo  "/" . $row_wybieranie_firm['dodatkowa_litera'] . "," ;} 
?>


<?php if ($row_wybieranie_firm['nr_lokalu'] != 0){
          echo "lok. " . $row_wybieranie_firm['nr_lokalu'] . ",";} 
?>


<?php echo substr($row_wybieranie_firm['kod_pocztowy'], 0, 2) . "-" . substr($row_wybieranie_firm['kod_pocztowy'], 2, 3) . " "; 
?>

<?php echo $row_wybieranie_firm['miasto']; 
?>
        </div>


<?php } while ($row_wybieranie_firm = mysql_fetch_assoc($wybieranie_firm)); 
?>

<p>
</p>  
  <div id="kopiowanie_email">
    <input type="submit" name="kopiuj_email" id="kopiuj_email" value="Kopiowanie email" tabindex="3">
  </div>
</form> 
</body>
</html>
<?php
mysql_free_result($imie_nazwisko);

mysql_free_result($wybieranie_firm);
?>

Following code generates lot of email addresses with checkbox right side of the email link. I would like to select some of the checkboxex and post the value to the destination site.
For example I would like to select second, third and tenth chceckbox and when I press Kopiowanie email button all tree values will be posted to the second site as array. Currently only last value of the while loop posts to the destination site independently which checkbox I choose.
Please can someone help me?

Recommended Answers

All 5 Replies

Hi,

somewhat unrelated but something you should really start doing..
Separate your php codes more from your HTML.. this is very messy code I started reading it to try and help you with your problem but it is so messy I stopped trying to read it all.

generally with checkboxes just name them something like:
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car

then your $_POST['vehicle'] will be an array which you can loop over with foreach()

eg:

foreach($_POST['vehicle'] as $vehval){
    echo $vehval;
}

Your code looks good to me, I have read it all through and can't see any mistakes. I replicated your list of checkboxes and ran it and it works fine, returning an array because you named the elements with [] (unlike the poster above). How are you testing the value of zaznaczenie_email[] ? Did you try the "get" method for the form, are all the variables in the URL?

OK I know about it. I'll try to explain.
After parse above code I have html result looks like:

<!--Div Tag nazy firmy -->
<div id="nazwa_firmy">
        <form name="szczegoly_firmy" method="post" action="szczegoly.php">

    Centrum Konferencyjne Zielna    
        <input type="submit" name="firma_szczegoly" id="firma_szczegoly" value="Szczegóły" tabindex="1"> 

        <input type="hidden" name="id_firmy" id="id_firmy" value="1">     

        </form>
</div>

<div id="adres_www">
      <a href="http://www.centrumzielna.pl/">www.centrumzielna.pl/</a>
    </div>
    <form name="kopiowanie_email" method="post" action="email.php">  
      <div id="adres_email">
       <a href="mailto:katarzyna@fwpn.org.pl">katarzyna@fwpn.org.pl</a>
        <input type="checkbox" name="zaznaczenie_email[]" id="zaznaczenie_email[]" tabindex="2" value="katarzyna@fwpn.org.pl"><label for="zaznaczenie_email"></label>


      </div>
      <div id="szczegoly">
ul.     

Zielna 
37, 



00-108 
Warszawa        </div>


<p>
</p>

<!--Div Tag nazy firmy -->
<div id="nazwa_firmy">
        <form name="szczegoly_firmy" method="post" action="szczegoly.php">

    Image LTD Sp. z o.o.    
        <input type="submit" name="firma_szczegoly" id="firma_szczegoly" value="Szczegóły" tabindex="1"> 

        <input type="hidden" name="id_firmy" id="id_firmy" value="2">     

        </form>
</div>

<div id="adres_www">
      <a href="http://imageltd.pl">imageltd.pl</a>
    </div>
    <form name="kopiowanie_email" method="post" action="email.php">  
      <div id="adres_email">
       <a href="mailto:agata@imageltd.pl">agata@imageltd.pl</a>
        <input type="checkbox" name="zaznaczenie_email[]" id="zaznaczenie_email[]" tabindex="2" value="agata@imageltd.pl"><label for="zaznaczenie_email"></label>


      </div>
      <div id="szczegoly">
ul.     

??kowa 
29, 



90-554 
?�d?        </div>



<p>
</p>  
  <div id="kopiowanie_email">
    <input type="submit" name="kopiuj_email" id="kopiuj_email" value="Kopiowanie email" tabindex="3">
  </div>
</form> 
</body>
</html>

As you can see I have many of <input type="checkbox" element with different value, but even if I checked the checkbox with katarzyna@fwpn.org.pl value and press Kopiowanie email button it sends NULL value. It only works when I check value with agata@imageltd.pl no other. I don't know why? Maby do while loop is not suitable for checkboxes?

Adam
GET method is not suitable due public sending values unlike POST is invisible. Besides the URL would be very long cause I have 6k emails in my database and If someone choose for example 500?

You want to be using foreach, not while to display your results from the form

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.