Search the Community
Showing results for tags 'elseif'.
-
Salut, sunt nou pe RST si intr-ale programarii! Invat php si am ceva probleme la if-uri! This is the html: <html> <head> <title>Piese auto</title> </head> <body> <h1>Piese auto</h1> <h2>Introduceti comanda</h2> <form action="processorder.php" method=post> <table border="0"> <tr bgcolor=#cccccc> <td width="150">Piesa</td> <td>Pret</td> <td width="15">Cantitate</td> </tr> <tr> <td>Anvelope</td> <td><center>$100</center></td> <td align="center"><input type="text" name="tireqty" size="3" maxlength="3" />bucati</td> </tr> <tr> <td>Sticle de ulei</td> <td><center>$10</center></td> <td align="center"><input type="text" name="oilqty" size="3" maxlength="3" />bucati</td> </tr> <tr> <td>Bujii</td> <td><center>$4</center></td> <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3" />bucati</td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Introdu comanda" /></td> </tr> </table> </form> <h3>Valoare TVA: 19%</h3> </body> </html> And this...php file: <html> <head> <title>Piese auto - Comanda introdusa</title> </head> <body> <h1>Piese auto</h1> <h2>Comanda introdusa</h2> <?php echo'<p>Comanda procesata la '; echo date('H:i, jS F'); echo '<p>'; $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; if($totalqty == 0) { echo 'Nu ai comandat nimic<br/>'; } elseif(is_numeric($tireqty) && is_numeric($oilqty) && is_numeric($sparkqty) && is_int($tireqty) && is_int($oilqty) && is_int($sparkqty)) { echo '<p>Ai comandat urmatoarele:</p>'; if($tireqty > 0) { echo $tireqty. ' anvelope<br />'; } else { echo 'Nu ai comandat anvelope!<br />'; } if($oilqty > 0) { echo $oilqty. ' sticle de ulei<br />'; } else { echo 'Nu ai comandat ulei!<br />'; } if($oilqty > 0) { echo $sparkqty. ' bujii<br />'; } else { echo 'Nu ai comandat bujii!<br />'; } } else { echo 'Trebuie sa introduci <u>doar numere intregi</u>(ex.: 3, 6, 14)<br />'; } /* echo 'Total piese: ' .$totalqty.'<br />'; echo '<br />'; echo '<p>Obiecte comandate: </p>'; echo $tireqty. ' anvelope;<br />'; echo $oilqty. ' sticle de ulei;<br />'; echo $sparkqty. ' bujii;<br />';*/ $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo 'Subtotal: $' .number_format($totalamount, 2). '<br />'; echo '<br />'; $taxrate = 0.19; $totalamount = $totalamount * (1 + $taxrate); echo 'Total(TVA inclus): $' .number_format($totalamount, 2); ?> </body> </html> Tocmai ce am scapat de o eroare strasanta(Parse error: syntax error, unexpected T_ELSE in....), acum am rezolvat, dar indiferent de ce as scrie in campurile din fisierul html, scriptul php imi sare peste elseif-ul care ar trebui sa verifice is_int, is_numeric si $totalqty > 0, $oilqty > 0...., deci sare peste el si trece direct la else, in concluzie, imi afiseaza(indiferent ce as completa in forumular) "Trebuie sa introduci doar numere intregi (ex.: 3, 6, 14) si cu totalul si subtotalul... Nu stiu cum sa-l fac sa intre in bucla de la elseif(sau care e problema) ca sa verifice conditiile alea...si apoi pe cele din if-urile incluse in bucla lui elseif! Scuzele mele daca m-am explicat ambiguu! Multumesc!