Dear All,
To upload the text file content into a table, I wrote the following code.
<?php
$aryInput = file("C:/Program Files/Apache Group/Apache/htdocs/myphpworks/todb.txt", "r");
$user = "root";
$pass = "root";
$db = "myworks";
$dbh = mysql_connect ("localhost",$user, $pass);
if (! $dbh)
{
print "Error connecting to the Database Engine<br>";
}
mysql_select_db ($db);
echo "<br>";
for($i=0;$i<count($aryInput);$i++)
{
$aryInputLine=explode(" ",$aryInput[$i]);
$name=$aryInput[$i];
$id=$aryInput[$i];
echo "$name";
echo "$id";
$insstock=mysql_query("insert into class values('$name','$id')", $dbh);
}
?>
In this code "todb.txt" is the text file that contains data to be uploaded. I created table in MySQL as "create table class(name varchar(20), id integer(5));"
The code is running well but the problem is it is inserting 3 additional null values in "id" field. If I say select * from class where id='NULL', it is showing all the three rows. I don't know where I committed a mistake. So please debug the code and help me in this issue.
Thanking you.