插入不在mysqli中工作的值

时间:2016-02-05 08:32:14

标签: php mysql

我创建了两个表,员工和部门。现在,在department表中,我分配了一个外键,并为employee表分配了PK。如果查看数据,Ii可以加入表格。

如何在PHP中编写查询以进行插入和更新?

我的查询:

?php
include "connect.php";
if(isset($_POST["submit"]))
{
    $fname  = $_POST["fname"];
    $dept   = $_POST["dept"];


    $result = mysqli_query($mysqli, "INSERT INTO employee ( fname, department)
            (SELECT fname, department FROM employee LEFT JOIN department ON employee.id=department.dept_id) values ( '$fname', '$dept')");

    if($result)
        {
            echo "<script>alert('New employee register successfully!')</script>";
            echo "<script>window.open('register.php','_self')</script>";
        }
    else 
        {
            echo "<script>alert('something went wrong!')</script>";
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

 public static void main(String[] args) {
    Integer granddTotal = 0;
    HashMap<String, ArrayList<Integer>> map = new HashMap<String, ArrayList<Integer>>();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(2);
    list.add(8);
    list.add(16);
    list.add(3);
    map.put("Trouser", list);

    list = new ArrayList<Integer>();
    list.add(3);
    list.add(15);
    list.add(45);
    list.add(0);
    map.put("Shirt", list);

    list = new ArrayList<Integer>();
    list.add(2);
    list.add(7);
    list.add(14);
    list.add(2);
    map.put("Coat", list);

    list = new ArrayList<Integer>();
    list.add(3);
    list.add(10);
    list.add(30);
    list.add(1);
    map.put("Pant", list);


    for(ArrayList<Integer> listData : map.values()) {
        granddTotal = granddTotal + listData.get(2);
    }
    System.out.println(granddTotal);
}    

//忘了(``)登录值