Jump to content

Invoices to MySQL


sass

Recommended Posts

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
        )
)

Link to comment
Share on other sites

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 by Ch0cu3r
Link to comment
Share on other sites

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:

 

<?php
if($_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>';
        }
    }
    }
}
?>

Link to comment
Share on other sites

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 by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.