How can I........

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Razael
Forum Newbie
Posts: 7
Joined: Fri Jul 12, 2002 8:00 pm

How can I........

Post by Razael »

I was wondering if when someone submits a txt file and the contents of the text file can be inserted in a mysql table acording to the name of the textfile. and then reading the information that was inserted in the MySQL database, and then using the include form, the information is inserted into a HTML page. Can this be possible?!?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Don't know about the file name of text but you can insert the txt file's content in to MySQL:-

Code: Select all

<?php
//INSERT DATA INTO TABLE CALLED "txt" which has 2 fields (one is ID auto_incremented).

  $sql = "INSERT INTO txt VALUES(NULL,"&#123;$_POST&#1111;'TEXTFILE']&#125;")";
  $temp = mysql_query($sql);

//READ DATA
  $sql = "SELECT id FROM txt WHERE id = 'ID NUMBER'";
  $temp = mysql_query($sql);
  list($result) = mysql_fetch_array($temp);
   echo $result;
?>
This should work although I haven't tested it. :arrow:
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

When inserting into a table with an auto-increment do it like this



$sql = "INSERT INTO txt (textcontent) values ('$ValueToBeInserted')";

txt (textcontent) this part specifies all of the fields you want to insert into seperated by commas, you must do this if you are not inserting into all fields. Do not include the auto-increment field and do not try to pass NULL, as Takumas insert query would do.
Razael
Forum Newbie
Posts: 7
Joined: Fri Jul 12, 2002 8:00 pm

Post by Razael »

Thanks a lot guys!
Post Reply