CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   MYSQL/PHP problem (http://www.codingforums.com/showthread.php?t=258700)

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!";
    
?>


Old Pedant 04-26-2012 08:39 AM

The result of calling mysql_query(...) will be *either* a boolean false value (which you are testing for when you do if (!$ctq) ... ) *OR* a resource identifier.

When you simply do echo $ctg; PHP can't output anything more sensible than the nature of the resource identifier.

There is NO VALUE OR POINT WHATSOEVER in doing echo $ctg;

Instead, if you want to *use* the results of you mysql_query(), you must now call mysql_fetch_assoc($ctg) or mysql_fetch_array($ctg) (the first of those is generally easier to work with).

Go read the PHP documentation:
http://www.php.net/manual/en/function.mysql-query.php
http://www.php.net/manual/en/functio...etch-assoc.php
http://www.php.net/manual/en/functio...etch-array.php


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.