Dear All,
I tried to upload the contents of a text file data by constructing a MySQL table like this:
Create table class(name varchar(20),id integer(2));
My code to upload data is:
<?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];
print "\t<td width = 50%> $name</td>\n";
print "\t<td width = 50%> $id</td>\n";
$insstock=mysql_query("insert into class values('$name','$id')", $dbh);
}
?>
Now the problem with this code is it is not inserting the second value of the text file into database(i.e., number field). I don't know where I comitted a mistake. Please help me in this issue. I am strucked.