| loopsnhoops |
04-26-2012 04:41 AM |
MYSQL/PHP problem
Hi,
Creating a website where users can upload files then download them on another page. I've made it so users can upload their files now and I am currently working on the downloading portion. Here is my code and the problem:
PHP Code:
<?php
$Server="xxxx";
$User="xxxx";
$Password="xxxx";
$Database="xxxx";
$con = mysql_connect($Server,$User,$Password);
if(!$con){
die("Couldn't Connect " . mysql_error());
}
mysql_select_db($Database,$con);
$sql = "SELECT * FROM IB2FILES";
$ctq = mysql_query($sql,$con);
if (!$ctq)
{
die("SQL Error! Query is $query<br />Error is ".mysql_error());
}
echo "Complete";
echo "<br />";
echo $ctq;
?>
After running through this code I get this on the next page:
Complete
Resource id #3
The problem here is that I have 3 files on the IB2FILES table and they have 5 fields (id(int),name(varchar),type(varchar),size(int),content(mediumBLOB).
I have no idea what Resource id #3 means but I keep getting that... Help Please!!!
Thanks in advance!
I don't know if it is relevant but here is the user input and upload handling code:
Form Code:
Code:
<form action="show.php" method="post" enctype="multipart/form-data">
<!-- <p style="font-size:20px">Upload a file:</p> -->
<tr><td> IB2:
<input type=radio name="grade" value="IB2" />
<br />
IB1:
<input type=radio name="grade" value="IB1" />
<br />
FY:
<input type=radio name="grade" value="FY" />
<br />
Y2:
<input type=radio name="grade" value="Y2" />
<br />
Y1:
<input type=radio name="grade" value="Y1" /> <br /> </td></tr>
<tr><td><input type="file" method="post" name="file" enctype="multipart/form-data" />
<input type="submit" name="submit" value="Upload File" />
Upload Code:
PHP Code:
<?php
//if (isset($_POST['submitb'])) {
$TheGrade = $_POST['grade'];
$Server="xxxx";
$User="xxxx";
$Password="xxxx";
$Database="xxxx";
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$file = $_FILES['file']['tmp_name'];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "image/pjpeg")))
{
if($_FILES["file"]["size"] < 5242880){
if($TheGrade==IB2){
$gradetable="IB2FILES";
} elseif($TheGrade==IB1){
$gradetable="IB1FILES";
} elseif($TheGrade==FY){
$gradetable="FYFILES";
} elseif($TheGrade==Y2){
$gradetable="Y2FILES";
} elseif($TheGrade==Y1){
$gradetable="Y1FILES";
} else {
echo "Connection error: No grade submission";
$gradetable=null;
echo $gradetable;
}
$connection = mysql_connect($Server, $User, $Password);
if(!$connection){
die("Couldn't Connect" . mysql_error());
}
$size = "'" . $size . "'";
$type = "'" . $type . "'";
$name = "'" . $name . "'";
mysql_select_db($Database, $connection);
$query = "INSERT INTO " . $gradetable . " (name,type,size) VALUES (" . $name . "," . $type . "," . $size . ")";
$table = mysql_query($query,$connection);
if (!$table)
{
die("SQL Error! Query is $query<br />Error is ".mysql_error());
}
} else {
echo "File size is too large";
}
} else {
$fte = "'" . "filelist.html" . "'" . "," . "'" . "File type not accepted. Please review the page below." . "'";
echo "<script type=text/javascript>
window.open(" . $fte . ")
</script>";
}
echo "File Uploaded!";
?>
|