On Thu, May 3, 2007 3:23 pm, Marcelo Wolfgang wrote: > 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") Browsers will probably NOT populate these reliably... Mac Safari, might, for example, choose "application/x-pdf" for the PDF file. You really can't rely on 'type' to be useful in any way, shape, or form. See various recent thread regarding "mime_magic" and other options. > && ($_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)"); That's not a query, that's a result... And you aren't checking it to see if it's an error, and you're not using http://php.net/mysql_error to find out what the error is. > mysql_close(); > > echo($user_Query) . "<br />"; //outputs nothing (? I suck at debugin > queries) And once you have closed the connection mysql_close() the result is GONE, so if you do want to see it, you'd need it to be before the mysql_close() probably. It won't be very interesting, really, as it will be FALSE if your SQL is messed up, and just a number from 1 to N (where N is the number of queries you have sent) if the query succeeded. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php