DragonWar% 2014-03-28 08:42 采纳率: 0%
浏览 5

人口下降

How can I get value from database using AJAX? I am creating salary slip in this when I select department auto populate employee name then select employee name auto populate Bank A/c No. and Basic salary. I tried using this code but getting problem in last drop down.

function dep(str) {
    var a;
    if (window.XMLHttpRequest) {
        a = new XMLHttpRequest();
    }
    a.onreadystatechange = function () {
        if (a.readyState == 4) {
            document.getElementById("empid").innerHTML = a.responseText;
        }

    }
    a.open("GET", "emp.php?j=" + str, true);
    a.send();
}

function employee(str) {
    //alert("hello");
    var b;
    if (window.XMLHttpRequest) {
        b = new XMLHttpRequest();
    }
    b.onreadystatechange = function () {
        if (b.readyState == 4) {
            document.getElementById("kam").innerHTML = b.responseText;
        }

    }
    b.open("GET", "ac.php?k=" + str, true);
    b.send();
}

function ac(str) {
    var d;
    if (window.XMLHttpRequest) {
        d = new XMLHttpRequest();
    }
    d.onreadystatechange = function () {
        if (d.readyState == 4) {
            document.getElementById("ja").innerHTML = d.responseText;
        }
    }
    d.open("GET", "insert.php?m=" + str, true);
    d.send();
}

PHP Coding

<?php
    //error_reporting(0);
    include("db.php");
    if(isset($_REQUEST['j']))
    {
        $g=$_REQUEST['j'];
        $sel=mysql_query("select * from employees where depid='$g'");
        while($l=mysql_fetch_array($sel))
        {
        ?>
            <option value="<?php echo $l[0];?>"><?php echo $l[1]. " ". $l[2];?></option>
        <?php
        } 
    }

    if(isset($_REQUEST['k']))
    {
        $o=$_REQUEST['k'];
        echo $sel1=mysql_query("select ac from salary where empid='$o'");
        while($i=mysql_fetch_array($sel1))
        {
        ?>
         <option value="<?php echo $i[0];?>"><?php echo $i[0];?></option>
        <?php 
        }
    }


    if(isset($_REQUEST['m']))
        {
        $ko=$_REQUEST['m'];
        echo $sel5=mysql_query("select basicsalary from salary where ac='$ko'");
        while($i1=mysql_fetch_array($sel5))
        {
        ?>
            <option value="<?php echo $i1[0];?>"><?php echo $i1[0];?></option>
        <?php 
        }
    }
    ?>

my database file :

<?php 
mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("payslip") or die(mysql_error()); 
?>
  • 写回答

1条回答 默认 最新

  • weixin_33725807 2014-03-28 10:29
    关注

    This not a solution, just an attempt to debug your code.

    Please read PHP.

    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    
    $conn = mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("payslip") or die(mysql_error());
    
    if (isset($_GET['m'])) {
        $ko = $_GET['m'];
        $sel5 = mysql_query("select basicsalary from salary where ac='$ko'", $conn);
    
        if (!$sel5) {
            die(mysql_error());
        }
    
        $options = "";
        while ($i1 = mysql_fetch_array($sel5, MYSQL_NUM)) {
            $options .= "<option value={$i1[0]}>{$i1[0]}</option>
    ";
        }
        mysql_close($conn);
        echo $options;
    } else {
        echo "empty data request";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀