0

I would like to ask some help in inserting data from texfile to a database table....i created a php code to execute in inserting the files to the table but i have no luck in importing it...can anyone know to do this?help me please.

enter image description here

current php code:

<?php
$host= "localhost";
$user= "root";
$pass= "";
$db="klayton";

$connect= mysql_connect($host,$user,$pass);
if (!$connect)die ("Cannot connect!");
mysql_select_db($db, $connect);

$file = fopen("tblApplicants.txt","r");  

while( $applicants = fgets($file) )
{
  $sql = "INSERT INTO tb_applicants( aic,name ) VALUES ('$applicants')"; 
  mysql_query($sql);
}    
?>
1

1 Answer 1

1

Read each line from this file,skip every second line $i%2 == 0 do break; explode it at " | " and get second ( $row[1] ) and nextone ( $row[2] ), then trim it, and make sql insert. Try to do at this way

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.