0

This is my PHP function:

  <?php 
             function input_bill()
            {
        $servername = "localhost";
        $conusername = "root";
        $conpassword = "";
        $dbname = "annapoorna";
        $dsn='mysql:dbname='.$dbname.';host='.$servername;
        $conn = new PDO($dsn, $conusername, $conpassword);
            $date="";
            $category_value="";
            $item_value="";
            $vendor_value="";
            $unit_value="";
            $price_rate_value=0;
            $quantity_value=0;
            $vat_value=0;
            $freight_value=0;
            $other_charges_value=0;
            $total_value=0;  

           if(!empty($_POST['datepicker'])&& !empty($_POST['category']) && !empty($_POST['name'])&& 
              !empty($_POST['vendor_name']) && !empty($_POST['Unit']) && !empty($_POST['Price_per_Unit'])
                   && !empty($_POST['Quantity']) && !empty($_POST['Freight_charges']) && !empty($_POST['Other_charges'])
                   && !empty($_POST['VAT']))
           {
            $date = date("Y-m-d",strtotime($_POST['datepicker']));

            $category_value=$_POST['category'];

            $item_value=$_POST['name'];

            $vendor_value=$_POST['vendor_name'];

            $unit_value=$_POST['Unit'];

            $price_rate_value=$_POST['Price_per_Unit'];

            $quantity_value=$_POST['Quantity'];

            $freight_value=$_POST['Freight_charges'];

            $other_charges_value=$_POST['Other_charges'];

            $vat_value=$_POST['VAT'];
            } 
            else
            {
                echo '<script type="text/javascript">alert("Please enter all values!");</script> ';
            }
            $total_value= ($price_rate_value * $quantity_value)+$freight_value+$other_charges_value+$vat_value;

            $sql='INSERT INTO bill(date, category, item, vendor, unit, price_per_unit, quantity, vat, freight_charges, other_charges, total) '
        . 'values (:date,:category, :item,:vendor, :unit, :price_per_unit, :quantity, :vat, :freight_charges, :other_charges, :total)';
                 $sth=$conn->prepare($sql); 
                $sth->execute(array(':date'=>$date,':category'=>$category_value,':item'=>$item_value, ':vendor'=>$vendor_value,
                    ':unit'=>$unit_value,':price_per_unit'=>$price_rate_value,':quantity'=>$quantity_value,':vat'=>$vat_value,
                    ':freight_charges'=>$freight_value,':other_charges'=>$other_charges_value,':total'=>$total_value));              
            }
            ?>

And this is my JS.

        <script type="text/javascript">
            function input_bill_js() {
            $.ajax ({
            url: "Accounts.php",
            success: function( result ) {

    }
}   
        </script>

I just want to call this function, but it's not happening. How do I do it? As per my conditions, the insert query should execute, OR an alert message should display.

Vineet Basantani
  • 182
  • 1
  • 1
  • 10

2 Answers2

0

You are only call .php file. you have not call the function Plz call the function at bottom of the file like this

input_bill();

When this function called then your code should be execute

Akshay Sharma
  • 1,042
  • 1
  • 8
  • 21
0

its not answers it showing some mistake in your script

 <script type="text/javascript">
        function input_bill_js() 
       {
          $.ajax ({
           url: "Accounts.php",
          success: function( result ) 
          {

          }
        }); //missing here  ajax close 
      }   
    </script>
JYoThI
  • 11,977
  • 1
  • 11
  • 26