Php receives post data and writes it to mysql

Source: Internet
Author: User
Php receives post data and writes it to mysql. how does php receive txt text from remote post and write it to the mysql database at the same time? Complete Code! Suitable for extra points!
Txt text field format:
Student id, student name, student email, Student Address


Reply to discussion (solution)

Data table:

CREATE TABLE `student` (  `id` int(10) unsigned NOT NULL auto_increment,  `xid` varchar(20) NOT NULL,  `name` varchar(20) NOT NULL,  `email` varchar(100) NOT NULL,  `address` varchar(100) NOT NULL,  PRIMARY KEY  (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Postdemo. php
    
   Demo     
 '; Echo'NOStudent idStudent NameStudent emailStudent Address'; Foreach ($ result as $ row) {echo''; Echo''. $ Row ['id'].''; Echo''. $ Row ['xid'].''; Echo''. $ Row ['name'].''; Echo''. $ Row ['email'].''; Echo''. $ Row ['address'].''; Echo'';} Echo'';}?>
 

Thank you for your answers. The txt text is not submitted in a form. a remote client directly post the entire txt file, for example:
Post File name: good.txt
File content:
001
Wang Jun
Wangjun@126.com
No. 2, Piao Road, Qingdao city, Shandong province

Could you tell me if the background receiving code has changed?
How can I simulate the post good.txt file to the background using php?
Thank you!

Any data submitted using the post method can be received using the $ _ POST ['variable name'] method.

 

Upload a simulated file?

Why do I have to use files?

Use regular expression matching to find the corresponding data

Are you going to do this? I? Txt file, and then server? Is the txt? Rong? Inbound ??????

Fdipzone experts are good. I have not made it clear. now I want to repeat it: the txt file is not submitted as a form. it is a remote client that posts a txt file and writes it to the mysql database.
Example: post File name: good.txt, file content
001
Wang Jun
Wangjun@126.com
No. 2, Piao Road, Qingdao city, Shandong province

Because the remote client directly post the good.txt file, the submitted data does not have a variable name, but is a direct string. can it be received using $ _ POST?

File Stream?
The following example describes four steps: php post File Stream, receiving File Stream, analyzing file stream, and writing data to the database.
1. conn. php is used to connect to the database
2. list. php is used to display database table records.
3. add. php is used to receive stream files and analyze and write data to the database.
4. post. ph is used to send stream files
5.good.txt file for sending. the content is

001 Wang Jun, wangjun@126.com, No. 2, Piao Road, Qingdao city, Shandong province

If all the above files are placed in the root directory, they can be accessed using http: // localhost/file name.

First create a database
CREATE TABLE `student` (  `id` int(10) unsigned NOT NULL auto_increment,  `xid` varchar(20) NOT NULL,  `name` varchar(20) NOT NULL,  `email` varchar(100) NOT NULL,  `address` varchar(100) NOT NULL,  PRIMARY KEY  (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Conn. php
 


List. php
    
   Demo     
 '; Echo'NOStudent idStudent NameStudent emailStudent Address'; Foreach ($ result as $ row) {echo''; Echo''. $ Row ['id'].''; Echo''. $ Row ['xid'].''; Echo''. $ Row ['name'].''; Echo''. $ Row ['email'].''; Echo''. $ Row ['address'].''; Echo'';} Echo'';}?>


Add. php
 


Post. php
 Array ('method' => 'post', 'header' => 'Content-type: application/x-www-form-urlencoded ', 'content' => $ data); $ context = stream_context_create ($ opts); $ url = 'http: // localhost/add. php'; // The received urlfile_get_contents ($ url, false, $ context);?>


Perform the following steps to access http: // localhost/post. php
Then access http: // localhost/list. php
If list.php displays the content of the good.txt file, it indicates that the file is successful. each time post. php is run, a record is added to the data table.

The reply from fdipzone experts is often awesome. I will try it first and give it a score later.

Related Article

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.