Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在php中的查询工作得非常好,但它没有填充我的数据库_Php_Database_Mysqli - Fatal编程技术网

我在php中的查询工作得非常好,但它没有填充我的数据库

我在php中的查询工作得非常好,但它没有填充我的数据库,php,database,mysqli,Php,Database,Mysqli,`u\u mulder非常感谢你,你的回答对我帮助很大。。。我也用过 <?php function throw_ex($er) { throw new Exception($er); } if(isset($_POST['btn_add'])) { $stud_id = $_POST['stud_id']; $stud_lrn = $_POST['stud_lrn']; $stud_ln

`

u\u mulder非常感谢你,你的回答对我帮助很大。。。我也用过

<?php
    function throw_ex($er)
    {
        throw new Exception($er);
    }
    if(isset($_POST['btn_add']))
    {
        $stud_id = $_POST['stud_id'];
        $stud_lrn = $_POST['stud_lrn'];
        $stud_lname = $_POST['stud_lname'];
        $stud_fname = $_POST['stud_fname'];
        $stud_mname = $_POST['stud_mname'];
        $stud_contact = $_POST['stud_contact'];
        $stud_address = $_POST['stud_address'];
        $stud_barangay = $_POST['stud_barangay'];
        $stud_municipality = $_POST['stud_municipality'];
        $stud_province = $_POST['stud_province'];
        $stud_bday = $_POST['stud_bday'];
        $stud_bplace = $_POST['stud_bplace'];
        $stud_mother_name = $_POST['stud_mother_name'];
        $stud_mother_bday = $_POST['stud_mother_bday'];
        $stud_mother_occupation = $_POST['stud_mother_occupation'];
        $stud_mother_contact = $_POST['stud_mother_contact'];
        $stud_father_name = $_POST['stud_father_name'];
        $stud_father_bday = $_POST['stud_father_bday'];
        $stud_father_occupation = $_POST['stud_father_occupation'];
        $stud_father_contact = $_POST['stud_father_contact'];

        $check = mysqli_query($con,"SELECT * from tbl_studentprofile where stud_lname ='".$stud_lname."' and stud_mname = '".$stud_mname."' and stud_fname = '".$stud_fname."'");

        $ct = mysqli_num_rows($check);

        if($ct == 0)
        {
            $query = "INSERT INTO tbl_studentprofile(stud_id, stud_lrn, stud_lname, stud_fname, stud_mname, stud_contact, stud_address, stud_barangay,stud_municipality, stud_province, stud_bday, stud_bplace,stud_mother_name, stud_mother_bday,stud_mother_occupation,stud_mother_contact,stud_father_name,stud_father_bday,stud_father_occupation,stud_father_contact,)VALUES ('".$stud_id."','".$stud_lrn."','".$stud_lname."','".$stud_fname."','".$stud_mname."','".$stud_contact."','".$stud_address."','".$stud_barangay."','".$stud_municipality."','".$stud_province."','".$stud_bday."','".$stud_bplace."','".$stud_mother_name."','".$stud_mother_bday."','".$stud_mother_occupation."','".$stud_mother_contact."','".$stud_father_name."','".$stud_father_bday."','".$stud_father_occupation."','".$stud_father_contact."')";
            $run = mysqli_query($con,$query);

            if(!$query)
            {
                 throw_ex(mysqli_error());
            }else
            {
                echo '<script>alert("Passed query");</script>';
            }

        }else
        {
           echo "Duplicate";
        }
    }
?>

为了指出错误…再次感谢u_mulder:D

,所以问题是当我尝试用所述查询填充数据库时。。。。它向我发出“已通过查询”警报,但数据库未填充$query是一个字符串,并且它不是空的,所以$查询为false。这里需要检查的是$run变量。这是否回答了您的问题?
$run = mysqli_query($con,$query) or die(mysqli_error($con));