i have created a table called stocks, and have created a table called stocks with the following fields,
name, currentprice, time, date, percentage, previousprice1, previousprice2, previousprice3, other
This is my connect file,
Code: Select all
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatabase = "stocks";
$config_project = "Data Visualisation";
$config_author = "Sam Gibson";
$config_basedir = "http://127.0.0.1/FinalMajorProject/";
?>Code: Select all
<?php
session_start();
require("connect.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into stocks(name, currentprice, time, date, percentage, previousprice1, previousprice2, previousprice3, other ) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='import.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='text' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>AAL.L,3300.00, 4:35PM,03/07/2008,-141.00,3393.00,3417.00,3293.00,8884595
ABF.L,819.00, 4:35PM,03/07/2008,-5.50,821.00,826.00,810.00,3018890
ADM.L,859.50, 4:35PM,03/07/2008,-12.00,868.00,873.50,852.00,1772574
when i upload my csv doc i get error messges saying undefined index line15.
Can someone shed some light? Many Thanks, Sam