-2
<?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";
        }
    }
?>

`

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • So the problem is when i try to populate my database with the said query.... it gives me the 'Passed query' alert but the database is not populated – just dont be user123 Sep 23 '18 at 08:33
  • `$query` is a __string__ and it is not __empty__, so `!$query` is __false__. What you need to check here is `$run` variable. – u_mulder Sep 23 '18 at 09:00
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Feb 10 '20 at 22:48

1 Answers1

0

u_mulder big thanks man, your answer helped me alot... i also used

$run = mysqli_query($con,$query) or die(mysqli_error($con));

to point out the error...again big thanks to u_mulder :D