viciado 1 Denunciar post Postado Agosto 22, 2010 orderfrom.html <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <form action="processoder.php" method=post> <table border=0> <tr bgcolor=#cccccc> <td width=150>Item</td> <td width=15>Quantity</td> </tr> <tr> <td>Tires</td> <td align="center"><input type="text" name="tireqty" size="3" maxlength="3"></td> </tr> <tr> <td>Oil</td> <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td> </tr> <tr> <td>Spark</td> <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="Submit Order"></td> </tr> <tr> <td>How did you find Bob's</td> <td><select name="find"> <option value="a">I'm regular costumer</option> <option value="b">TV advertising</option> <option value="c">Phone directory</option> <option value="d">Word of mouth</option> </select> </td> </tr> </table> </form> processoder.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <?php $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; ?> <head> <title> Bob's Auto parts - Order Results </title> </head> <body> <h1>Bob's Auto Parts</h1> <h2>Order Results</h2> <?php echo "<p>order processed."; echo date('H:i, jS F'); echo '</p>'; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo 'Items ordered: '.$totalqty.'<br />'; if($totalqty == 0.00) { echo 'You did not order anything on the previous page!<br />'; } else { if($tireqty > 0) echo $tireqty.' tires<br />'; if($oilqty > 0) echo $oilqty.' bottles of oil<br />'; if($sparkqty > 0) echo $sparkqty.' spark plugs<br />'; } $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPROCE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPROCE; $totalamount = number_format($totalamount, 2, '.', ' '); echo '<p>Total of order is '.$totalamount.'</p>'; echo '<p>Address to ship to is '.$address.'</p>'; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t" .$sparkqty." spark plugs\t\$".$totalamount ."\t".$address."\n"; fopen("$DOCUMENT_ROOT\\C:\\WebServer\\Apache 2\\htdocs\\Teste\\orders.txt", 'ab'); if(!$fp) { echo '<p><strong> Your order could not be processed at this time. ' .'Please try again later.</strong></p></body></html>'; exit; } fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp); echo '<p>Order Written.</p>'; ?> </body> </html> freight.php <html> <body> <table border="0" cellpadding="3"> <tr> <td bgcolor="#cccccc" align="center">Distance</td> <td bgcolor="#cccccc" align="center">Cost</td> </tr> <?php $distance = 50; while($distance <= 250) { echo "<tr> \n <td align = 'right'>$distance</td>\n"; echo " <td align = 'right'>". $distance / 10 ."</td>\n</tr>\n"; $distance += 50; } ?> </table> </body> </html> O problema que eu tenho agora é que não aparece nenhuma mensagem de erro no NetBeans. Mais ao executar o programa, aparece a seguinte mensagem: Notice: Undefined index: address in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 8 Bob's Auto Parts Order Results order processed.22:23, 21st August Items ordered: 13 2 tires 5 bottles of oil 6 spark plugs Total of order is 274.00 Address to ship to is Notice: Undefined variable: date in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 59 Warning: fopen(C:/WebServer/Apache 2/htdocs\C:\WebServer\Apache 2\htdocs\Teste\orders.txt) [function.fopen]: failed to open stream: Invalid argument in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 63 Notice: Undefined variable: fp in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 65 Your order could not be processed at this time. Please try again later. Compartilhar este post Link para o post Compartilhar em outros sites
Bruno Augusto 417 Denunciar post Postado Agosto 22, 2010 Não sei como o NetBeans trabalha com PHP para te ajudar a reconfigurá-lo, mas quanto aos erros: Notice: Undefined index: address in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 8Isso significa que um índice chamado address não existe. Índices só existem em arrays, logo seria algo como $array['address']. Com isso vemos a linha do arquivo proccessorder.php. Nela você verá que tem $_POST['address']. O array superglobal $_POST é populado com o par chave/valor de name / value dos campos campos HTML da página que o disparou. Veja que no seu formulário não há nenhum campo com name="address". Daí o erro. Para sanar esse problema, trabalhe com isset() e empty() Notice: Undefined variable: date in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 59Não existe uma variável $date criada. Olhando o contexto do seu código, encontra-se uma chamada a date(). Considerando que esta é a data a ser usada, você deve atribuir a função à uma variável antes de usá-la. Warning: fopen(C:/WebServer/Apache 2/htdocs\C:\WebServer\Apache 2\htdocs\Teste\orders.txt) [function.fopen]: failed to open stream: Invalid argument in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 63 Notice: Undefined variable: fp in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 65 Your order could not be processed at this time. Please try again later Exatamente o mesmo erro que o anterior. Você está testando (IF) e utilizando [ fwrite() e fclose() ] um recurso que deveria estar armazenado em uma variévl $fp. Como você não a definiu, atribuindo o valor do seu fopen(), desencadeou vários erros. Compartilhar este post Link para o post Compartilhar em outros sites
viciado 1 Denunciar post Postado Agosto 22, 2010 Notice: Undefined index: address in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 8 Eu tentei arrumar adicionando ao orderfrom.html <tr> <td>Address</td> <td align="center"><input type="text" name="address" size="3" maxlength="30"></td> </tr>Porém não adiantou processoder.php ficou assim: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <?php $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; ?> <head> <title> Bob's Auto parts - Order Results </title> </head> <body> <h1>Bob's Auto Parts</h1> <h2>Order Results</h2> <?php $date = date('H:i, jS F'); echo "<p>order processed."; echo date('H:i, jS F'); echo '</p>'; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo 'Items ordered: '.$totalqty.'<br />'; if($totalqty == 0.00) { echo 'You did not order anything on the previous page!<br />'; } else { if($tireqty > 0) echo $tireqty.' tires<br />'; if($oilqty > 0) echo $oilqty.' bottles of oil<br />'; if($sparkqty > 0) echo $sparkqty.' spark plugs<br />'; } $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPROCE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPROCE; $totalamount = number_format($totalamount, 2, '.', ' '); echo '<p>Total of order is '.$totalamount.'</p>'; echo '<p>Address to ship to is '.$address.'</p>'; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t" .$sparkqty." spark plugs\t\$".$totalamount ."\t".$address."\n"; $fp = fopen("$DOCUMENT_ROOT\\C:\\WebServer\\Apache 2\\htdocs\\Teste\\orders.txt", 'ab'); if(!$fp) { echo '<p><strong> Your order could not be processed at this time. ' .'Please try again later.</strong></p></body></html>'; exit; } fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp); echo '<p>Order Written.</p>'; ?> </body> </html> Agora estou com esses erros: Notice: Undefined index: address in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 8 Bob's Auto Parts Order Results order processed.17:24, 22nd August Items ordered: 24 7 tires 8 bottles of oil 9 spark plugs Total of order is 816.00 Address to ship to is Warning: fopen(C:/WebServer/Apache 2/htdocs\C:\WebServer\Apache 2\htdocs\Teste\orders.txt) [function.fopen]: failed to open stream: Invalid argument in C:\WebServer\Apache 2\htdocs\Teste\processoder.php on line 65 Your order could not be processed at this time. Please try again later. Existe alguma IDE melhor q o NetBeans para PHP ? Compartilhar este post Link para o post Compartilhar em outros sites
Bruno Augusto 417 Denunciar post Postado Agosto 22, 2010 Dê um print_r() (envolto por tags <pre>) e veja o que o seu programa está recebendo em $_POST. Sobre o erro do fopen() significa que a função não pôde localizar o arquivo orders.txt Também pudera, olha o path que você está passando! Quanto ao editor, gratuito tem o Eclipse PDT No mais, se você não entende inglês, pode dar uma passadinha num tradutor online e ver o que as mensagens significam e aprender mais sobre elas, no manual. Compartilhar este post Link para o post Compartilhar em outros sites
viciado 1 Denunciar post Postado Agosto 23, 2010 Sobre o erro do fopen() significa que a função não pôde localizar o arquivo orders.txt Também pudera, olha o path que você está passando! Como assim o path q eu estou passando ? Compartilhar este post Link para o post Compartilhar em outros sites
VascoDaGama 2 Denunciar post Postado Agosto 23, 2010 fopen(C:/WebServer/Apache 2/htdocs\C:\WebServer\Apache 2\htdocs\Teste\orders.txt) Compartilhar este post Link para o post Compartilhar em outros sites
viciado 1 Denunciar post Postado Agosto 24, 2010 fopen(C:/WebServer/Apache 2/htdocs\C:\WebServer\Apache 2\htdocs\Teste\orders.txt) Vlw era isso msm Compartilhar este post Link para o post Compartilhar em outros sites