Jump to content
bubbles

PHP checkbox POST

Recommended Posts

Posted

Am urmatorul cod :

<?php

if ($_POST['pret_total'])
{
$checked = $_POST['produs'];
if (!$checked) { $totalprice='Nu ati selectat produse';} else {

foreach($checked as $item) {

$totalprice+=$item;
$totalprice.=' lei';
}
}
}

$result = mysql_query("SELECT * FROM produse");
while($row = mysql_fetch_array($result))
{
echo "
<tr>
<td width='200px' align='center'>
<img width='50px' style='border:1px solid #909090;' src='images/products/".$row['id'].".jpg'></td>
<td width='300px' align='center'>".$row['nume']."</td>
<td width='300px' align='center'>".$row['pret']." lei</td>
<td width='50px' align='center'><input type='checkbox' name='produs[]' value='".$row['pret']."' ></td>
</tr>";
}

?>

Cum as putea face ca produsele selectate sa imi mai apara inca o data pe pagina ?

Posted (edited)

There are often situations where a group of related checkboxes are needed on a form. The advantage of check box group is that the user can select more than one options. checkboxes are used to give visitors a choice of options.

Edited by evangilbort
Posted

O solutie ar fii ca inainte sa faci echo-ul in care le printezi sa le asignezi intr-un nou array. Dupa asta mai faci un foreach pe noul array si aia e.

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.   Paste as plain text instead

  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...