Jump to content

Recommended Posts

I've got a list with checkboxes and rows from a table like this:

 

checkbox 1, userid, sendid, date, subject, mess

checkbox 2, userid, sendid, date, subject, mess

.

.

 

So I have this code:

 

$i=0;

 

if(isset($_POST['submit']))

{ // if page is submitted echo the form

 

$result2 = mysql_query("SELECT * FROM Mail");

          while($row2 = mysql_fetch_array($result2)){

if ($_POST['email'][$i]!="")

{

echo $row2['userID'];

echo $row2['sendID'];

echo $row2['subject'];

echo $row2['senddate'];

}

  $i=$i+1;

  }

} // End  if (!isset($_POST['Submit']))

 

the code should echo the row where the checkbox is checked. The code works if you check many in a row, but when you check only one for ex checkbox5 with index 4, it allways echoes index 0. Can you see where the problem is??

Link to comment
https://forums.phpfreaks.com/topic/182900-get-checkbox-value/
Share on other sites

Not sure I entirely follow.

but...

 

$1=0;

 

You set the index to zero.

 

$i=0;  is set to start from the first checkbox. It's outside isset so if you press subit $ is not affected.

What the code does:

 

when submit is pressed:

1 it enters the if(isset($_POST['submit']))

2 get rows from table

3 as long as there are rows in table

4 if checkbox is checked (starting from 0), echo the row

5 increase $i with 1

 

say we have in list:

 

ckbox 1, Jake,Sam,work,091130

ckbox 2, Greg,Bobby,day off,091204

ckbox 3, Mr X,Gordon,vacation,091004

 

I check checkbox 3 in the list:

 

first:  checkbox 1 is not checked,$i=0, don't echo row, $i=1

second: checkbox 2 is not checked,$i=1, don't echo row, $i=2

third:  checkbox 3 is checked,$i=2, echo rows, $i=3

Link to comment
https://forums.phpfreaks.com/topic/182900-get-checkbox-value/#findComment-965570
Share on other sites

The problem is when I create the checkboxes:

 

$s=0;

<?php while($row = mysql_fetch_array($result)){ ?>

<input type="checkbox" value="Electricity" name="email[" . <? echo $s; ?> . "]">

<?php $s = $s + 1; } ?>

 

Do you see any wrong with the code above??

what I need is to create the checkboxes like this:

email[0]

email[1]

email[2]

.

.

 

Link to comment
https://forums.phpfreaks.com/topic/182900-get-checkbox-value/#findComment-965625
Share on other sites

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.