Uploading Data to MySQL Table from Desktop .csv File
Posted: Wed Apr 15, 2009 1:18 pm
Hello,
I am new to php and have problem uploading a .csv file residing in desktop to mysql table.
Wondering if I first need to bring file to the server or can I upload directly from desktop?
My sample code is below but it looks like the form values are not being pased to the php code as indicated by the empty fields in output. Just ran out of ideas and nothing jumps out. Any help is appreciated.
This is the output -->:
Description:
File to upload:
File ID: 7
File Name:
File Size:
File Type:
To upload another file Click Here
Here is the script -->:
<form method="post" action="test4.php" enctype="multipart/form-data">
Description:<br>
<input type="text" name="form_description" size="40">
<br>File to upload:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
mysql_connect("192.168.110.100","adm","pwhere");
mysql_select_db("mydata");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_type')");
$id= mysql_insert_id();
print "<p>File ID: <b>$id</b><br>";
print "<p>File Name: <b>$form_data_name</b><br>";
print "<p>File Size: <b>$form_data_size</b><br>";
print "<p>File Type: <b>$form_data_type</b><p>";
print "To upload another file <a href=http://www.yoursite.com/yourpage.html> Click Here</a>";
?>
I am new to php and have problem uploading a .csv file residing in desktop to mysql table.
Wondering if I first need to bring file to the server or can I upload directly from desktop?
My sample code is below but it looks like the form values are not being pased to the php code as indicated by the empty fields in output. Just ran out of ideas and nothing jumps out. Any help is appreciated.
This is the output -->:
Description:
File to upload:
File ID: 7
File Name:
File Size:
File Type:
To upload another file Click Here
Here is the script -->:
<form method="post" action="test4.php" enctype="multipart/form-data">
Description:<br>
<input type="text" name="form_description" size="40">
<br>File to upload:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
mysql_connect("192.168.110.100","adm","pwhere");
mysql_select_db("mydata");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_type')");
$id= mysql_insert_id();
print "<p>File ID: <b>$id</b><br>";
print "<p>File Name: <b>$form_data_name</b><br>";
print "<p>File Size: <b>$form_data_size</b><br>";
print "<p>File Type: <b>$form_data_type</b><p>";
print "To upload another file <a href=http://www.yoursite.com/yourpage.html> Click Here</a>";
?>