phatgreenbuds Posted December 16, 2006 Share Posted December 16, 2006 Can anyone explain why the code below does not actually upload the file to my database entry? I have a single entry (62) in my database with everything else updating properly but cannot add a file to it via this upload page. I have no idea what I am missing.[code]<HTML><HEAD><title>Upload and Finish!</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD><BODY><hr><div align="center"> <h3>To complete your request please upload the relevant request form below: </h3></div><form method="post" enctype="multipart/form-data"> <div align="center"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="20000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td> </tr> </table> </div></form><div align="center"> <?php$docrefu = "62";if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0){$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($tmpName));$content = addslashes($content);fclose($fp);if(!get_magic_quotes_gpc()){ $fileName = addslashes($fileName);}//MySQL Database Connectinclude 'dbcon.php'; $query = "INSERT INTO crdmain (reqfilename, reqfilesize, reqfiletype, reqfile)VALUES ('$fileName', '$fileSize', '$fileType', '$content')WHERE CRDNum = '$docrefu'";echo "<br>";echo "<br>File $fileName uploaded<br>";echo "<br>";echo "CRD# $docrefu is now submitted and pending approval.";echo "<br>";} ?></div></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/ Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 There is no call to mysql_query() in your code therefore nothing is being executed against your database. Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/#findComment-142578 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 Thank you for the reply. I changed the code to look like this:$query = mysql_query("INSERT INTO crdmain (reqfilename, reqfilesize, reqfiletype, reqfile)VALUES ('$fileName', '$fileSize', '$fileType', '$content')WHERE CRDNum = '$docrefu'");It still is not working and being such a NOOB I am sure its a matter of syntax. Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/#findComment-142613 Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 Well, for starters, you cannot use a WHERE clause in an INSERT statement. Are you trying to add a new record? If so, remove the WHERE.Also, try some debugging...[code=php:0]$query = mysql_query("INSERT INTO crdmain (reqfilename, reqfilesize, reqfiletype, reqfile) VALUES ('$fileName', '$fileSize', '$fileType', '$content')") or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/#findComment-142620 Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 Sorry, reread your post. If you trying to update a record you need to use an update statement.[code=php:0]$query = mysql_query("UPDATE crdmain SET reqfilename = '$fileName', reqfilesize = '$fileSize', reqfiletype = '$fileType', reqfile = '$content' WHERE CRDNum = '$docrefu'") or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/#findComment-142622 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 OHHHH DAMN! That was it...now I feel pretty noobish. Sincere thanks for the help. Link to comment https://forums.phpfreaks.com/topic/30904-solved-this-is-working-my-nerves/#findComment-142625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.