justAnoob Posted February 3, 2009 Share Posted February 3, 2009 Should there be a ";" at the end of the line that is marked below? Or are there other mistakes? <?php $host = "----------"; $username = "-------------"; $password = "-------------"; $db_name = "msimages"; $tbl_name = "UploadedFiles"; mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); if (!empty($_POST['upload'])) { foreach($_POST as $key => $value) { $$key = $value; } $connect->connect_db(mydatabase); // <----this line ??? if(isset($_POST['upload']) && $_FILES['upload_file']['size'] > 0) { $fileName = $_FILES['upload_file']['name']; $tmpName = $_FILES['upload_file']['tmp_name']; $fileSize = $_FILES['upload_file']['size']; $fileType = $_FILES['upload_file']['type']; $fp= fopen($tmpName, 'r'); $content = addslashes($content); fclose($fp); } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO UploadedFiles (name, size, type, content)VALUES('$fileName', '$fileSize', '$fileType', '$content')"; $result = mysql_query($query); if (!$result) { dberror (mysql_error(), $_SERVER['PHP_SELF'] ); echo mysql_error(); } header("Location: ------------.com"); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/ Share on other sites More sharing options...
Philip Posted February 3, 2009 Share Posted February 3, 2009 Yup, there needs to be a ;... however, where is "mydatabase" coming from? Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-753937 Share on other sites More sharing options...
trq Posted February 3, 2009 Share Posted February 3, 2009 however, where is "mydatabase" coming from? While were at it. Where is $connect coming from? Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-753940 Share on other sites More sharing options...
justAnoob Posted February 3, 2009 Author Share Posted February 3, 2009 Well, good question. Guess I have some more work to do. LoL. Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-753952 Share on other sites More sharing options...
Andy-H Posted February 3, 2009 Share Posted February 3, 2009 Your database connection and selection is established already. I would delete that line of code and remove the quotes (") around your variables. mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-753957 Share on other sites More sharing options...
Andy-H Posted February 3, 2009 Share Posted February 3, 2009 Should there be a ";" at the end of the line that is marked below? Or are there other mistakes? <?php $host = "----------"; $username = "-------------"; $password = "-------------"; $db_name = "msimages"; mysql_connect($host, $username, $password) or die("Could not connect."); mysql_select_db($db_name) or die("Could not find database"); if (!empty($_POST['upload'])) { extract($_POST); if(isset($_POST['upload']) && $_FILES['upload_file']['size'] > 0) { $fileName = $_FILES['upload_file']['name']; $tmpName = $_FILES['upload_file']['tmp_name']; $fileSize = $_FILES['upload_file']['size']; $fileType = $_FILES['upload_file']['type']; if ( file_exists($tmpName) ) { $content = file_get_contents($tmpName); } } $fileName = mysql_real_escape_string($fileName); $fileSize = (int)$fileSize; $fileType = mysql_real_escape_string($fileType); $content = mysql_real_escape_string($content); $query = "INSERT INTO UploadedFiles (name, size, type, content) VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; $result = mysql_query($query)or die (mysql_error()); header("Location: ------------.com"); exit; } ?> Try that? Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-753963 Share on other sites More sharing options...
justAnoob Posted February 4, 2009 Author Share Posted February 4, 2009 Hey, thanks for the help. Much appreciated. I'm guessing that this still isn't all that secure of an upload script, but it is a start. Now I just need to only allow certain types of images(png gif jpg) and a max size limit. I guess it is time to start reading. Thanks again. If anyone else would like to add something,,,, feel free. Quote Link to comment https://forums.phpfreaks.com/topic/143689-noobie-here-just-need-a-little-help/#findComment-754036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.