PHP writes files--saves user-submitted data to a file in the server

Source: Internet
Author: User
Tags flock php write
first write the HTML page:

    
 
      Order Page

Jason's Shopping list



then write the server-side script file in PHP processorder.php

     
 
  
     <title>Order results</title>

Jason's Shopping Cart

Order results

Time of order submission: '. $date. '

'; Echo '

Your specific shopping list is:

'; Get the total quantity of goods $total _qty=0; $total _qty= $cloths + $shoes + $glasses; Echo ' Total number of items: '. $total _qty. '
'; if ($total _qty==0) {echo ' You have not purchased any items! '; }else{if ($cloths >0) {echo $cloths. ' Pieces mens
'; } if ($shoes >0) {echo $shoes. ' Pair of shoes
'; } if ($glasses >0) {echo $glasses. ' Pair of glasses
'; }}//Get the total price of merchandise $total _amount=0.00; Const CLOTHS_PRICE=100; Const SHOES_PRICE=300; Const GLASSES_PRICE=28; $total _amount= $cloths *cloths_price+ $shoes *shoes_price+ $glasses *glasses_price; $total _amount=number_format ($total _amount,2, '. ', '); Echo '

Total Merchandise: ¥ '. $total _amount. '

'; Echo '

Delivery address: '. $address. '

'; Set the file output content and format $out _put_string= $date. \ t ". $cloths." piece mens \ t ". $shoes." Two Shoes \ t ". $glasses." Pair of glasses \t\ Total Price: ¥ ". $total _amount." Delivery address: \ t ". $address." \ n "; Open file, (Append mode + binary mode) @ $fp =fopen ("$DOCUMENT _root/l02/files/orders.text", ' ab '); Flock ($FP, LOCK_EX); if (! $fp) {echo]

Your order has not been submitted for completion, please try again.

"; Exit }//Writes data to file Fwrite ($fp, $out _put_string,strlen ($out _put_string)); Flock ($FP, lock_un); Close file stream fclose ($FP); echo "

Data Save complete

";? >

Finally, the Orders.txt file is generated under the files file, the contents of the file are (can be appended):


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP write file-the user submitted data saved to the server file, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.