Ltj_bukem Posted October 4, 2007 Share Posted October 4, 2007 I'm trying to create a script to upload files to the database, from what I have read I have to first upload the file to the sever and then read the contents into MYSQL. Here's the script but nothing appears in the database or the server. <html> <head> <title>Upload</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .box { font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } --> </style> </head> <body> <? if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, $fileSize); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $dbhost = '****'; $dbuser = '*****'; $dbpass = '******'; $dbname = '*****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname) $query = "INSERT INTO download (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); //include 'library/closedb.php'; } ?> <form action="" method="post" enctype="multipart/form-data" name="uploadform"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/ Share on other sites More sharing options...
shocker-z Posted October 4, 2007 Share Posted October 4, 2007 change mysql_query($query) or die('Error, query failed'); to mysql_query($query) or die('Error, insert image query failed: '.mysql_error()); that will echo the error in the sql back to you. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/#findComment-361600 Share on other sites More sharing options...
Ltj_bukem Posted October 4, 2007 Author Share Posted October 4, 2007 I'm getting a 'Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\htdocs\uploadform.php on line 33' this is the following line(s) $query = "INSERT INTO download (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; I'm guessing something is not right with the database. Quote Link to comment https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/#findComment-361711 Share on other sites More sharing options...
shocker-z Posted October 4, 2007 Share Posted October 4, 2007 $query = "INSERT INTO download (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; you had a random "." in the midle that wasnt needed. Liam Quote Link to comment https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/#findComment-361819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.