File uploading and saving info on mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I'm developing for my first time an upload file form which will populate a sql insert query, I think I got everything working fine, but the data isn't been saved on the database. Can someone help me with what I'm doing wrong here ?

the code follow:

<?php
if (($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("../downloads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../downloads/" . $_FILES["file"]["name"]);
      }
    }
  }
else
  {
  echo "Invalid file";
  }
$title = $_POST["title"];
$filePath =   "../downloads/" . $_FILES["file"]["name"];
if($_FILES["file"]["type"] == "application/pdf"){
	$fileType = "pdf";
} else if ($_FILES["file"]["type"] == "application/msword"){
	$fileType = "doc";
}
echo($title) . "<br />"; //outputs 'yada' ( correctly as I've typed on the form; echo($filePath) . "<br />"; //outputs '../downloads/66321-Estrutura.doc' and I can check that the file is there;
echo($fileType) . "<br />"; //outputs 'doc' this is correct;

mysql_connect("localhost",$db_user,$db_pass) or die (mysql_error());;
mysql_select_db ($db_table);
$user_Query = mysql_query("INSERT INTO tb_downloads (var_title, var_filepath, var_filetype, dt_data, bol_active) VALUES ('$title', '$filePath','$fileType','NOW(),1)");
mysql_close();

echo($user_Query) . "<br />"; //outputs nothing (? I suck at debugin queries)

header("Location: http://www.w3ol.com.br/50congresso/adm/downloads.php";); // I know that this won't work while I echo something on the page, but the echo is there for debug only

?>

TIA
Marcelo Wolfgang

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux