File Upload From Web Page to Replace Data

From: Date: Wed, 14 Jun 2000 19:02:39 +0000
Subject: File Upload From Web Page to Replace Data
Groups: php.general 
Request: Send a blank email to php-general+get-1857@lists.php.net to get a copy of this message
I started out knowing nothing about PHP or MySQL a month ago, but I've cobbled together a site that's almost finished at: http://www.dallasbureau.com With my admin pages at: http://www.dallasbureau.com/admin.html The site is for testing, so if you look, feel free to try the logins and passwords, and the login and password for the admin area is admin/hardies. On the main site, the data listed is different depending on who logged in, with a calendar to show available delievery dates. While I've got a few kinks yet to iron out, the one thing that I've run against the wall about is the uploading of new database information. In my case, I need to have the user upload a tab-delimited text file with information to REPLACE the data in my products table. On one page, I've put the following code to have the user browse to his file and send it: <FORM ENCTYPE="multipart/form-data" ACTION="ul2.php" METHOD=POST> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000"> Send this file: <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" VALUE="Send File"> </FORM> Then, on the ul2.php page, I've put some code to handle it, but clearly its very wrong. The code above is borrowed and I've never heard of $file_type and $file_size for one, but even when I comment-out those lines below, my script still falls apart. This list has been a valuable source twice in the past. The people here are incredible. Don Smith NewsVideo.com <? if ((!$name) || (!$password) || (!$company) || (!$email)) { header("Location: http://www.dallasbureau.com/admin_add.php"); exit; } $connection = mysql_connect("localhost", "username", "password") or die ("Couldn't connect to server."); $db = mysql_select_db("dallasbureau", $connection) or die ("Couldn't select database."); if ($file_size("$userfile") > 100000) { echo "<p>File too large!</p>"; echo "<p><a href=\"ul.php\">Return to File Upload Page</a></p>"; } if ($file_type("$userfile") != "txt") { echo "File is not of .TXT type!"; echo "<a href=\"ul.php\">Return to File Upload Page</a>"; } $sql = "LOAD DATA LOCAL INFILE $userfile INTO TABLE products"; $result = mysql_query($sql) or die ("Couldn't load the table with new information."); (code here to verify that new table information has been uploaded) break; default: include("login_form5.inc"); } ?> </body> </html>

« previous php.general (#1857) next »