This is the example of my text file:
Name: Chloe
Class: 1A
School: EEE
This is my database:
Name Class School
How do I input the text file data into my database using php? Thank you.
This is the example of my text file:
Name: Chloe
Class: 1A
School: EEE
This is my database:
Name Class School
How do I input the text file data into my database using php? Thank you.
This will help read a line in the file into an array:
see: http://www.homeandlearn.co.uk/php/php10p7.html
now once you have the 3 lines, you just need to get the data into your database....
here's some info on the command you will probably need to use to insert/update the data http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
here's some useful info on reading files : http://www.w3schools.com/PHP/php_file.asp
See more info http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Load DATA INFILE 'file_name' into table table_name FIELDS TERMINATED BY '\t'
PHP code
$pdo = new PDO(connection settings);
$pdo->exec($mysql_query);
LOAD DATA is a fine tool, but it's not the right one for this job. It requires a particular format that isn't present in the data here. For starters, fields aren't delimited by \t. Each field is on its own line, and there is more data on each line than needs to be stored. OP just needs to parse the file - trivially done in this case - and run a quick INSERT query. The only reason I haven't answered this myself is that it's extremely obviously homework, and standard practice for HW questions is to have OP show her work first, then guide her rather than just "sending teh codez".