html - query failed when upload pdf file to mysql via php -


i trying upload button able upload pdf file database faced problems. database used mysql.

pop out window user key in document

<form method="post" action="upload.php" enctype="multipart/form-data">     <div>         <label for="citation">citation</label>         <textarea name="citation" id="citation" placeholder="enter text here..."></textarea>     </div>     <div>         <label for="abstract">abstract</label>         <textarea name="abstract" id="abstract" placeholder="enter text here..."></textarea>     </div>         <p>upload file here</p>         <input type="hidden" name="max_file_size" value="2000000">         <input name="userfile" type="file" id="userfile">&nbsp;         <br/>          <input name="submit" type="submit" value="upload" style="width: 150px">                 <a class="close" href="#close"></a>     </form> 

this upload.php

<?php         // connect database         $host="localhost"; // host name          $username="root"; // mysql username          $password=""; // mysql password          $db_name="is"; // database name          $tbl_name="publication"; // table name           $conn = mysql_connect("$host", "$username", "$password");          if(! $conn )         {           die('could not connect: ' . mysql_error());         }          mysql_select_db($db_name);          $cit=mysql_real_escape_string($_post['citation']);         $abs=mysql_real_escape_string($_post['abstract']);          if(isset($_post['submit']) && $_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);         }          $query = "insert publication ('citation','abstract','file_name', 'file_size', 'file_type', 'file_content' ) values ('$cit','$abs','$filename', '$filesize', '$filetype', '$content')";          mysql_query($query) or die('error, query failed');            echo "<script type='text/javascript'>alert('file $filename uploaded!');                 window.location.href='home_unlogin.php';             </script>";         }          mysql_close($conn); ?> 

at next show error, query failed , have no idea whats wrong it.

    $query = "insert publication (`citation`,`abstract`,`file_name`, `file_size`, `file_type`, `file_content`) values ('$cit','$abs','$filename', '$filesize', '$filetype', '$content')"; 

or can use without wrapping field names

    $query = "insert publication (citation, abstract, file_name, file_size, file_type, file_content) values ('$cit','$abs','$filename', '$filesize', '$filetype', '$content')"; 

because field names standard names not reserved word or contains special chars.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -