str4kt Posted February 14, 2009 Share Posted February 14, 2009 So I have an assignment where I have to create a .html and .php file. My .html works perfectly, but my .php doesn't. <html> <head> <title>Bob's Auto Parts</title> </head> <body> <h1>Bob's Auto Parts</h1> <h2>Order Form</h2> <form action="processorder2.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=left><input type="text" name="tireqty" size=3 maxlength=3></td> </tr> <tr> <td>Oil</td> <td align=left><input type="text" name="oilqty" size=3 maxlength=3></td> </tr> <tr> <td>Spark Plugs</td> <td align=left><input type="text" name="sparkqty" size=3 maxlength=3></td> </tr> <tr> <td>Shipping Address</td> <td align=center><input type="text" name="address" size=40 maxlength=40></td> </tr> <tr> <td colspan=2 align=center><input type=submit value="Submit Order"></td> </tr> </table> </form> </body> </html> Thats my .html and it works perfect, but its my .php that doesnt. <?php // create short variable names $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; ?> <html> <head> <title>Bob's Auto Parts and Winery - Order Results</title> </head> <body> <h1>Bob's Auto Parts and Winery</h1> <h2>Order Results</h2> <?php $date = date("F - d - Y"); echo '<p>Order processed at '; echo $date; echo '</p>'; echo '<p>Your order is as follows: </p>'; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo 'Items ordered: '.$totalqty.'<br />'; if( $totalqty == 0) { 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('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; -1- G:\public_html\processorder2.php Friday, October 10, 2008 1:43 PM $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"; // open file for appending $filename = "orders.txt"; echo '<p>filename is '.$filename.'</p>'; @ $fp = fopen($filename, 'ab'); echo '<p>open to lock </p>'; flock($fp, LOCK_EX); 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)); flock($fp, LOCK_UN); fclose($fp); echo '<p>Order written.</p>'; ?> </body> </html> It is supposed to end up looking like this when you get to the .php part after you try the site out: Bob's Auto Parts and Winery Order Results Order processed at February - 13 - 2009 Your order is as follows: Items ordered: 3 1 tires 1 bottles of oil 1 spark plugs Total of order is 114.00 Address to ship to is 1 filename is orders.txt open to lock Your order could not be processed at this time. Please try again later. Can anyone help? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/ Share on other sites More sharing options...
Maq Posted February 14, 2009 Share Posted February 14, 2009 What exactly displays? Are there errors? Is everything on that page (processorder2.php)? Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761812 Share on other sites More sharing options...
str4kt Posted February 14, 2009 Author Share Posted February 14, 2009 I get something like this after I enter in the numbers on the html page. All errors come from the php page. Bob's Auto Parts Order Results Order processed at '; echo $date; echo ' '; echo ' Your order is as follows: '; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty + $coolqty + $wiperqty; echo 'Items ordered: '.$totalqty.' '; if( $totalqty == 0) { echo 'You did not order anything on the previous page! '; } else { if ( $tireqty>0 ) echo $tireqty.' tires '; if ( $oilqty>0 ) echo $oilqty.' bottles of oil '; if ( $sparkqty>0 ) echo $sparkqty.' spark plugs '; if ( $coolqty>0 ) echo $coolqty.' coolant '; if ($wiperqty>0 ) echo $wiperqty.' wiper blades '; } $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); define('COOLPRICE', 1); define('WIPERPRICE', 3); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE + $coolqty * COOLPRICE + $wiperqty * WIPERPRICE; $totalamount = $totalamount + ($totalamount * .10); $totalamount=number_format($totalamount, 2, '.', ' '); echo ' Total of order is '.$totalamount.' '; echo ' Address to ship to is '.$address.' '; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t" .$sparkqty." spark plugs\t".$coolqty." coolant\t".$wiperqty." wiper blades\t\$".$totalamount ."\t". $address."\n"; // open file for appending @ $fp = fopen("$DOCUMENT_ROOT/folder2/orders.txt", 'ab'); flock($fp, LOCK_EX); if (!$fp) { echo ' Your order could not be processed at this time. ' .'Please try again later. '; exit; } fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); fclose($fp); echo ' Order written. '; ?> Click HERE to see all submitted orders. Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761813 Share on other sites More sharing options...
allworknoplay Posted February 14, 2009 Share Posted February 14, 2009 it doesn't look like your page is parsing PHP..... Your PHP code shouldn't be showing up at all.... Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761816 Share on other sites More sharing options...
Maq Posted February 14, 2009 Share Posted February 14, 2009 Maybe it's the wrong MIME type being server, try putting this at the top: Your code works for me... Bob's Auto Parts and Winery Order Results Order processed at February - 13 - 2009 Your order is as follows: Items ordered: 9 2 tires 3 bottles of oil 4 spark plugs Total of order is 246.00 Address to ship to is phpville filename is orders.txt open to lock Order written. Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761821 Share on other sites More sharing options...
str4kt Posted February 14, 2009 Author Share Posted February 14, 2009 The first page works fine. It tells me to enter in the numbers and such, and when I hit submit, it takes me to the next php page, but its all wrong/ with errors. Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761822 Share on other sites More sharing options...
str4kt Posted February 14, 2009 Author Share Posted February 14, 2009 Anyone know? Quote Link to comment https://forums.phpfreaks.com/topic/145144-need-help-with-php-keep-getting-errors/#findComment-761836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.