drnmslpz42661 2016-06-13 06:05
浏览 166

如何从我的JS调用php函数? [重复]

This question already has an answer here:

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.

</div>
  • 写回答

2条回答 默认 最新

  • doubiankang2845 2016-06-13 06:08
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题