File uploading and saving info on mysql

From: Date: Thu, 03 May 2007 20:23:28 +0000
Subject: File uploading and saving info on mysql
Groups: php.general 
Request: Send a blank email to php-general+get-254370@lists.php.net to get a copy of this message
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

« previous php.general (#254370) next »