Jump to content

TRaWolTa89

New Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by TRaWolTa89

  1. Sorry about the code tag. First time posting. I replaced the code with the one you gave me. You forgot to close ) in if statement and it gave me an error, but I fixed it. :happy-04: Now it gives me this error:" Notice: Undefined variable: file_put_contents in C...." This is the line:

    if(!$file_put_contents ($file, $outputstring, FILE_APPEND|LOCK_EX) { 

  2. Hello

     

    I'm having a problem with my php script. It's about writing lines to a text file. The script runs normally without any errors, but it leaves the text file empty, no matter how many times I run it. I'm using WAMP server.

     

    Here's the code:

     

     

    <?php //kratke varijable

    $tireqty=$_POST['tireqty'];

    $oilqty=$_POST['oilqty'];

    $sparkqty=$_POST['sparkqty'];

    $adress=$_POST['adress'];

    $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

    $date = date('H:i, jS F Y');

    ?>

    <html>

    <head>

    <meta charset="utf-8">

    <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 at ".date ('H:i, jS F Y')."</p>";

    echo "<p>Your order is as follows: </p>";

     

    $totalqty=0;

    $totalqty=$tireqty+$sparkqty+$oilqty;

    echo "Item ordered: ".$totalqty."<br />";

     

     

    if ($totalqty == 0) {

    echo "You didn't order anyting from previous page!<br />";

    } else {

    if($tireqty>0)

    echo $tireqty." tires<br />";

    if($oilqty>0)

    echo $oilqty." oil<br />";

    if($sparkqty>0)

    echo $sparkqty." sparks<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 />';

     

    $taxrate = 0.20; // local sales tax is 20%

    $totalamount = $totalamount * (1 + $taxrate);

    echo 'Total including tax: $'.number_format($totalamount,2).'<br />';

    echo '<p>Adress to ship to is '.$adress.'</p>';

     

    $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"

    .$sparkqty." spark plugs\t\$".$totalamount

    ."\t". $adress."\n";

    //open file for appending

    @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');

     

    if(!$fp) {

    echo "<p><strong> Your order could not be processed at this time.<br>

    Please try again later. </strong></p></body></html>";

    exit;

    }

    flock($fp, LOCK_EX);

    echo fwrite($fp, $outputstring, strlen($outputstring));

    flock($fp, LOCK_UN);

    fclose($fp);

     

    echo "<p>Order written.</p>";

    ?>

    </body>

    </html>

     

     

    Thanks in advance for any help.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.