File uploading to mysql
hi all ,
im havin a prob. i wrote a script to add files to mysql database.. files are adding but files information is not dispalyin ? wats wrong with this ??????
Here s the coding..!!!!!
<?
global $strDesc;
global $fileUpload;
global $fileUpload_name;
global $fileUpload_size;
global $fileUpload_type;
$strDesc =$_POST['strDesc'];
@$fileUpload =$_POST['fileUpload'];
if(empty($strDesc) || $fileUpload == "none")
die ("Please Enter a both description and file");
$host = "localhost";
$database = "myfiles";
$fileHandle = fopen($fileUpload,"r");
$fileContent =fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$sConnect = mysql_connect($host) or die ("Couldn't connect to the database $database");
$dConnect = mysql_select_db($database,$sConnect);
$dbquery = "INSERT INTO myBlobs VALUES";
$dbquery .= "(0,'$strDesc','$fileContent','$fileUpload_type')";
mysql_query($dbquery) or die ("Couldn't add file to database");
echo "<h1>File Uploaded</h1>";
echo "The details of the uploaded file are shown below:<br><br>";
echo "<b>File name:</b> $fileUpload_name <br>";
echo "<b>File type:</b> $fileUpload_type <br>";
echo "<b>File size:</b> $fileUpload_size <br>";
echo "<b>Uploaded to:</b> $fileUpload <br><br>";
?>
Thanx..!!
Sajee Da Best
Read this page: http://ww.php.net/manual/en/function...etch-assoc.php
You didn't query the DB with any SELECT statement, nor did you fetch and of the information from teh DB, you just uploaded it.
There is a very simple example on the page (above) that should explain to you in detail what you are missing.
Answers to all your questions can be found at: PHP Manual
thanx for the reply.. i went there before , but dude i ve dnt know how it can done my project..
Sajee Da Best
If you went to the page i gave you and you don't still don't understand how to get results from the DB, then I'm not sure anything I tell you will help unless I just write the code for you.
You can try this, but I havent checked it. YOU have to insert the fied name into the SELECT statement:
PHP Code:
<?
global $strDesc ;
global $fileUpload ;
global $fileUpload_name ;
global $fileUpload_size ;
global $fileUpload_type ;
$strDesc = $_POST [ 'strDesc' ];
@ $fileUpload = $_POST [ 'fileUpload' ];
if(empty( $strDesc ) || $fileUpload == "none" )
die ( "Please Enter a both description and file" );
$host = "localhost" ;
$database = "myfiles" ;
$fileHandle = fopen ( $fileUpload , "r" );
$fileContent = fread ( $fileHandle , $fileUpload_size );
$fileContent = addslashes ( $fileContent );
$sConnect = mysql_connect ( $host ) or die ( "Couldn't connect to the database $database " );
$dConnect = mysql_select_db ( $database , $sConnect );
$dbquery = "INSERT INTO myBlobs VALUES" ;
$dbquery .= "(0,' $strDesc ',' $fileContent ',' $fileUpload_type ')" ;
mysql_query ( $dbquery ) or die ( "Couldn't add file to database" );
$dbquery_results = mysql_query ( 'SELECT field, names FROM myBlobs' ); //YOU MUST ENTER THE FIELD NAMES HERE
while ( $row = mysql_fetch_assoc ( $dbquery_results ))
{
foreach( $row as $key => $value )
{
echo "KEY = " . $key . " <br />\nValue = " . $value . " <br />" ;
}
}
mysql_close ( $sconnect );
echo "<h1>File Uploaded</h1>" ;
echo "The details of the uploaded file are shown below:<br><br>" ;
echo "<b>File name:</b> $fileUpload_name <br>" ;
echo "<b>File type:</b> $fileUpload_type <br>" ;
echo "<b>File size:</b> $fileUpload_size <br>" ;
echo "<b>Uploaded to:</b> $fileUpload <br><br>" ;
?>
Answers to all your questions can be found at: PHP Manual
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks