Jump to content

[SOLVED] This is working my nerves!


phatgreenbuds

Recommended Posts

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 Connect
include '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

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.
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]

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.