LeighJor
asked on
PHP getting checkbox to work in listed array
Hi still having problems which I thought were solved despite the efforts of EE help (due to my limited knowledge most likely)
Anyway I'm trying a different approach I'm listing names dynamically from database but iwant to put qty box to be filled by customer next to each name plus a chekcbox so that if chekbox ticked then the name and qty is submitted.eg
Checkbox Name Qty
(from db)
x Apple 7
Pear
x Banana 6
This is the code Im working with
Thanks in advance
<tr>
<?php
$i = 0
while($bname = $imageList->fetch_assoc()) {
?>
<tr><td><input type="text" name="bname_$i" value="<? echo $bname['bname']; ?>" disabled></td>
<td><input type="text" name="price_$i" value="<? echo $bname['price']; ?>" disabled></td>
<td><input type="text" name="qty_$i" value=""></td>
</tr>
<?php
$i++;
}
?>
</tr>
<tr>
Anyway I'm trying a different approach I'm listing names dynamically from database but iwant to put qty box to be filled by customer next to each name plus a chekcbox so that if chekbox ticked then the name and qty is submitted.eg
Checkbox Name Qty
(from db)
x Apple 7
Pear
x Banana 6
This is the code Im working with
Thanks in advance
<tr>
<?php
$i = 0
while($bname = $imageList->fetch_assoc())
?>
<tr><td><input type="text" name="bname_$i" value="<? echo $bname['bname']; ?>" disabled></td>
<td><input type="text" name="price_$i" value="<? echo $bname['price']; ?>" disabled></td>
<td><input type="text" name="qty_$i" value=""></td>
</tr>
<?php
$i++;
}
?>
</tr>
<tr>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry forgot to mention, notice the square brackets added incase you were wondering about what was different.
<input type="checkbox" id="someid" name="bname[]" value="<?php echo $bname['bname']; ?>" >
<input type="checkbox" id="someid" name="bname[]" value="<?php echo $bname['bname']; ?>" >
If you were wanting to retain the same variable name, the most ideal would be something like:
<input type="checkbox" id="someid" name="bname_<?php echo $i; ?>[]" value="<?php echo $bname['bname']; ?>" >
This also echos $i and makes it part of the checkbox name.
<input type="checkbox" id="someid" name="bname_<?php echo $i; ?>[]" value="<?php echo $bname['bname']; ?>" >
This also echos $i and makes it part of the checkbox name.
ASKER
No I cant get the $bname list up.
I can get vert checkboxes and qty input box but not the list from the db. Any thoughts?
appreciate your help
I can get vert checkboxes and qty input box but not the list from the db. Any thoughts?
appreciate your help
ASKER
here is the code i've got so far
$getImages = 'SELECT * FROM journal ORDER BY bname';
$imageList = $conn->query($getImages) or die(mysqli_error($conn));
?>
<FORM ACTION="Email.php" method=post>
<table border=0>
<tr>
<td width=15>Name
</td>
<?php /*?><td ><input type="text" name="name" size="3" maxlength="3"></td><?php */?>
<td width=15>Quantity
</td>
<?php /*?><td ><input type="text" name="qty" size="3" maxlength="3"></td><?php */?>
</tr>
<tr>
<?php /*?><td>
<p>
<label for="bname">BULBS:</label> </td><?php */?>
<td>
<?php
while($bname = $imageList->fetch_assoc()) { ?>
<tr><td><input type="checkbox" id="someid" name="bname[]" value="<?php echo $bname['bname']; ?>" ></td>
<td ><input type="text" name="qty" size="3" maxlength="3"></td></tr><? php }?>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>
</body>
</html>
$getImages = 'SELECT * FROM journal ORDER BY bname';
$imageList = $conn->query($getImages) or die(mysqli_error($conn));
?>
<FORM ACTION="Email.php" method=post>
<table border=0>
<tr>
<td width=15>Name
</td>
<?php /*?><td ><input type="text" name="name" size="3" maxlength="3"></td><?php */?>
<td width=15>Quantity
</td>
<?php /*?><td ><input type="text" name="qty" size="3" maxlength="3"></td><?php */?>
</tr>
<tr>
<?php /*?><td>
<p>
<label for="bname">BULBS:</label>
<td>
<?php
while($bname = $imageList->fetch_assoc())
<tr><td><input type="checkbox" id="someid" name="bname[]" value="<?php echo $bname['bname']; ?>" ></td>
<td ><input type="text" name="qty" size="3" maxlength="3"></td></tr><?
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>
</body>
</html>
I'm not sure of your problem at the moment, are you saying that <?php echo $bname['bname']; ?> does not echo anything?
What exactly does your $bname variable store? And is it an array or a normal variable?
What exactly does your $bname variable store? And is it an array or a normal variable?
ASKER
It does not echo anything at the moment
$bname should be echo of datadase column filled from 'SELECT * FROM journal ORDER BY bname'
$bname should be echo of datadase column filled from 'SELECT * FROM journal ORDER BY bname'
ASKER
i was using this before but it would not submit so needed a checkbox so that each checked row would be sent.
<?php
$i = 0;
while($bname = $imageList->fetch_assoc()) {
?>
<tr> <td><input type="text" name="bname_$i" value="<? echo $bname['bname']; ?>" disabled></td>
<td><input type="text" name="price_$i" value="<? echo $bname['price']; ?>" disabled></td>
<td><input type="text" name="qty_$i" value=""></td><tr>
<?php
$i++;
}
?>
<?php
$i = 0;
while($bname = $imageList->fetch_assoc())
?>
<tr> <td><input type="text" name="bname_$i" value="<? echo $bname['bname']; ?>" disabled></td>
<td><input type="text" name="price_$i" value="<? echo $bname['price']; ?>" disabled></td>
<td><input type="text" name="qty_$i" value=""></td><tr>
<?php
$i++;
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry to take so long to get back to you nplib.
Thanki you very much that does enable me to display on page that "The Price for abracadabr is 20 dollars and they want 20 amount"
How do i get that into the sent message though.
Cheers and many thanks
Leighjor
Thanki you very much that does enable me to display on page that "The Price for abracadabr is 20 dollars and they want 20 amount"
How do i get that into the sent message though.
Cheers and many thanks
Leighjor
I'm not sure what your asking for.
Can you give me an example?
Can you give me an example?
ASKER
How do I get the ouput of this :
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
echo "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount";
}
into this:
$message = wordwrap($message, 70);
Send
mail('caffinated@example.c om', 'My Subject', $message);
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
echo "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount";
}
into this:
$message = wordwrap($message, 70);
Send
mail('caffinated@example.c
you could do this, but I don't know the full structure of your code,
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
$str = "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount";
$message = wordwrap($str, 70);
Sendmail('caffinated@examp le.com', 'My Subject', $message);
}
or
$tempArray = array();
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
array_push($tempArray, "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount");
}
foreach ($tempArray as $t) {
$message = wordwrap($t, 70);
Sendmail('caffinated@examp le.com', 'My Subject', $message);
}
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
$str = "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount";
$message = wordwrap($str, 70);
Sendmail('caffinated@examp
}
or
$tempArray = array();
foreach ($getCheckBoxData as $x) {
$temp = explode("-", $x);
array_push($tempArray, "The Price for ".$temp['1']." is ".$temp['2']." dollars and they want ".$getQTY[$temp['0']]." amount");
}
foreach ($tempArray as $t) {
$message = wordwrap($t, 70);
Sendmail('caffinated@examp
}
ASKER
that gave me the boxes but thats all- no data