sass Posted October 20, 2013 Share Posted October 20, 2013 We have a house with 30 apartments. We have created a webpage where the bookkeeper uploads monthly invoices for each apartment.Every resident has their own account to look up the invoices.Currently, the accountant enters all invoices manually, one at a time (PHP file upload).Currently, each apartment has a separate folder where the invoice has been placed and for each invoice PHP code creates an entry to MySQL table.Accounting software allows exporting invoices automatically, but what should be the PHP code that allows the files that are exported from accounting software to reach to MySQL database and to the correct folders?The webpage uses MySQL 5.6 and PHP 5.4 server.Accounting software sends the following parameters: $_REQUEST:Array( [action] => upload [uid] => username [pwd] => password [month] => 10 [year] => 2013 [house] => [apartment] => 28)$_FILE:Array( [file] => Array ( [name] => -10-2013-28.pdf [type] => application/pdf [tmp_name] => /tmp/phpoSs5Wv [error] => 0 => 1891 )) Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/ Share on other sites More sharing options...
Ch0cu3r Posted October 20, 2013 Share Posted October 20, 2013 (edited) Currently, the accountant enters all invoices manually, one at a time (PHP file upload). .... but what should be the PHP code that allows the files that are exported from accounting software to reach to MySQL database and to the correct folders? The code will be same PHP code you're using for manually uploading the files. Edited October 20, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454635 Share on other sites More sharing options...
sass Posted October 20, 2013 Author Share Posted October 20, 2013 My manual upload is wery basic as i am beginner. Accounting software sends more values than i use, like month, year, there must be separate login and thats a problem for me. Do i have to add separate user with password to MySQL for accounting software, make PHP login code for software and add new tables to database? I tried this but nothing happens if i am uploading invoices, no errors and no invoices in database. This is my manual upload code: <?phpif($_POST['upload']) { $category = $_POST['category']; if($category == "0") { echo '<script>alert("You don´t choose category")</script>'; } else { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("invoices/".$_POST['apartment']."/".$_FILES["file"]["name"])) { echo '<script>alert("This file exists")</script>'; } else { $date = date("d.m.Y"); move_uploaded_file($_FILES["file"]["tmp_name"],"invoices/".$_POST['apartment']."/".$_FILES["file"]["name"]); mysql_query("INSERT INTO invoices (apartment,invoice,date) VALUES ('".$_POST['apartment']."','".$_FILES["file"]["name"]."','".$date."')"); echo '<script>alert("Invoice uploaded")</script>'; echo '<script>document.location.href="?p=10"</script>'; } } }}?> Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454646 Share on other sites More sharing options...
Ch0cu3r Posted October 20, 2013 Share Posted October 20, 2013 (edited) The code you posted above should process the file upload just fine. However you will need to change if($_POST['upload']) { to if(isset($_POST['upload']) || $_REQUEST['action'] == 'upload') { and change $_POST['apartment'] to $_REQUEST['apartment'] Is the uid (username) and pwd (password) the same credentials required for authorising the user on your site? Edited October 20, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454651 Share on other sites More sharing options...
sass Posted October 20, 2013 Author Share Posted October 20, 2013 Thank you for help, I will try it. For authorising the user i have "usern" and "passw", but I can change them to "uid" and "pwd". Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454655 Share on other sites More sharing options...
Ch0cu3r Posted October 20, 2013 Share Posted October 20, 2013 Yeah, try changing it and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454656 Share on other sites More sharing options...
sass Posted October 21, 2013 Author Share Posted October 21, 2013 Thank you, it working fine now. Quote Link to comment https://forums.phpfreaks.com/topic/283122-invoices-to-mysql/#findComment-1454758 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.