I am working on a script that allows a user to upload a .pdf file that will then be stored in a MySQL DB table.

Here is the SQL for creating the table:
CREATE TABLE upload (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)

And here is the script, upload.php:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../psustyle.css" />
<link rel="stylesheet" type="text/css" href="../OMSstyle.css" />
<link rel="StyleSheet" href="/dTree/dtree.css" type="text/css" />
<?php include '/var/www/html/OMSinclude.php'; ?>
<title>Operational Monitor and Statistics</title>
</head>
<body OnKeyPress="return disableKeyPress(event)">
<?php
include '/var/www/html/header.php';
?>

<?php
session_start();

if ($_SESSION['highestRole'] != 'Admin') exit;

echo "<form method='POST' enctype='multipart/form-data'>";
echo "<table width='350' border='0' cellpadding='1' cellspacing='1' class='box'>";
echo "<tr>";
echo "<td width='246'>";
echo "<input type='hidden' name='MAX_FILE_SIZE' value='2000000'>";
echo "<input name='userfile' type='file' id='userfile'>";
echo "</td>";
echo "<td width='80'><input name='upload' type='submit' class='box' id='upload' value=' Upload '></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>

<?php
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);
}

$dbh = new PDO('mysql:host='.$SESSION['OpsDBServer'].'.ops.tns.its.xxx.edu;dbname='.$SESSION['OpsDB'], $SESSION['yoM'], $SESSION['aMa']);
$sql = "INSERT INTO upload (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

$dbh->query($sql) or die("Error");

echo "<br>File $fileName uploaded<br>";
}
?>

<?php
include '/var/www/html/footer.php';
?>
</body>
</html>

My query, $dbh, a PDO object, keeps dieing and giving me the message "Error". I am not sure what is wrong any help would be greatly appreciated.

    The first thing that's wrong is that you're not using $dbh->errorCode() or $dbh->errorInfo() to get information about the error.

      I just used those two methods and I got a value of "42S02" for the error code and "Array" for the error info. I have not researched the code yet, as I just did this a minute ago, but I thought I would post anyway.

        Thanks for the help weedpacket. sorry about my last post too, I newbed out and forgot about print_r hah. I figured out the issue though.

        /thread

          Write a Reply...