0

Hello
I have a form for a shoping cart that input even the value 0. How can i program php to not insert into table the products

$row['Denumire_produs']

where the quantyti=$cantitate is 0
Here is the form input

$query="select*from produse";
  
           ?>    <form action="cumpar.php"  method="post">
<td><input type="text" name="cantitate[]" value=" " size="1"/></td></tr>
<input type="hidden" name="Denumire_produs[]" value="<?php echo $row['Denumire_produs'];?>"/>
<input type="hidden" name="id_produs[]" value="<?php echo $row['id_produs'];?>"/>
<input type="hidden" name="Pret[]" value="<?php echo $row['Pret'];?>"/><?php ;}//Navigaton?>

AND HERE IS THE
QUERY FOR ARRAY

$numrows=mysql_num_rows($results);
     
        
    if ($numrows>0){
    $cantitate=($_POST['cantitate']);
    $denumire=($_POST['Denumire_produs']);
    $id_produs=($_POST['id_produs']);
    $pret=($_POST['Pret']);
    //extrage un array ---foarte tare bolean
    
 for($i=0;$i<$limit;$i++){

    $queryi="insert into livrari_luni
                (user_id,
                id_programare,
                id_produs,
                denumire_produs,
                Pret,
                cantitate
                )values(
                '". $userid . "',
                '". $id_prog . "',
                '". $id_produs[$i] ."',
                '". $denumire[$i] . "',
                 '". $pret[$i] . "',                
                '". $cantitate [$i] ."')";
                $resulti = mysql_query($queryi)
                or die (mysql_error);

thanks in advance

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by cristi08
0

Test for the condition you want to eliminate in your loop.

for($i=0;$i<$limit;$i++){
    if(intval($cantitate[$i]) < 1) continue;   // skip to next entry in the array;
    $queryi="insert into livrari_luni
...
0

Test for the condition you want to eliminate in your loop.

for($i=0;$i<$limit;$i++){
    if(intval($cantitate[$i]) < 1) continue;   // skip to next entry in the array;
    $queryi="insert into livrari_luni
...

Thank you it working grate. :)

0

I use

if($cantitate[$i])> 1)

and it seem to be ok this way to;

0

Any variables with the values false/0/NULL/"" are considered to execute false in PHP

#execcute if $cantitate[$i] is not null
if($cantitate[$i]){
  //this part of the array is not NULL.....
}

Would also be fine.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.