Jump to content

Unknown column in 'field list' error is a headache


jmahdi

Recommended Posts

Hi there

 

I'm trying to insert audi files' records into mysql database this is how the records insertion looks like:

 

$fileName = $_FILES['uploaded']['name'];//name
$tmpName  = $_FILES['uploaded']['tmp_name'];//temp location
$fileSize = $_FILES['uploaded']['size'];//size of the file
$fileType = $_FILES['uploaded']['type'];//type of file
$error    = $_FILES['uploaded']['error'];//verifys errprs
$ext = substr($fileName, strrpos($fileName, '.') +1); //this will get the extention out of the file name e.g. .mp3



//check that a file is passed by and no errors
if(isset($fileName) && $error == 0 && $fileSize != 0){

//condition to accept only certain file types/extentions
if($ext == "mp3" || $ext == "wma" || $ext == "wav"){

//get file content
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
    
}


        //query to retrieve user's id
        $userid = mysql_query("select userID from user where username = '$username'");
//to get id by username
$row = mysql_fetch_assoc($userid);
$userid = $row['userID'];

$query = "INSERT INTO tracks (trackName, userID, tag, price, file, fileName, fileSize, fileType)
    VALUES ('$tname','$userid','$tag','$price','$content','$fileName','$fileSize' , '$fileType)";
    
mysql_query($query) or die (mysql_error());

 

when i send it i get this error:  Unknown column 'application' in 'field list' i did set data type for the fileType field to varchar.  when i remove the fileType all together the record is inserted successfully  into database though. ?!! can anyone help please

Link to comment
Share on other sites

I believe you are missing a quote

 

change this

$query = "INSERT INTO tracks (trackName, userID, tag, price, file, fileName, fileSize, fileType)
    VALUES ('$tname','$userid','$tag','$price','$content','$fileName','$fileSize' , '$fileType)";

 

to this

$query = "INSERT INTO tracks (trackName, userID, tag, price, file, fileName, fileSize, fileType)
    VALUES ('$tname','$userid','$tag','$price','$content','$fileName','$fileSize','$fileType')";

 

 

Pikachu2000 is too fast

Link to comment
Share on other sites

Add the missing single quote after '$fileType and see if that takes care of the problem. It's also a good idea to echo the query string along with the error while you're developing.

 

Oh...silly me, i shoul've noticed  :wtf: anyways thanks for the quick reply....i think i need a rest  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.