Error Query in PHP


  1. Posts : 6
    Windows 10 x64
       #1

    Error Query in PHP


    I've got this error in php

    Error Query [insert into priv_qualification (nokp,qualification_type,qualification,awarding_body,qualification_date,gezzette_date,experience,q_d oc) VALUES (:a1,:b1,:c1,:d1,:e1,:f1,:g1,:h1)]

    and this is my coding

    $strSQL = ("insert into peribadi_details (nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES (:b,:c,:d,:e,:f,:g,:h,:i,:j)");
    $objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysqli_num_rows($objQuery);

    HELP ME PLEASE
      My Computer


  2. Posts : 4,049
    W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
       #2

    Weird


    I'm not sure how the query and error message are related.

    They seem to be about 2 different tables ("priv_qualification" vs "peribadi_details") with a different number of values (8 vs 9).

    I assume that ":a1,:b1, etc." are some type of variables, but we never used that format in my PHP courses.
      My Computer


  3. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #3

    Hi happy memorial, is there any additional information that you could give us that might help?
      My Computer


  4. Posts : 6
    Windows 10 x64
    Thread Starter
       #4

    I've changes the coding like this

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name=test_input($_POST['name']);
    $nokp=test_input($_POST['nokp']);
    $homeadd=test_input($_POST['homeadd']);


    $teleoff=test_input($_POST['teleoff']);
    $restele=test_input($_POST['restele']);
    $mobiletele=test_input($_POST['mobiletele']);
    $position=test_input($_POST['position']);
    $grade=test_input($_POST['gred']);
    $serviceduration=test_input($_POST['serviceduration']);
    }


    $name=$_POST['name'];
    $nokp=$_POST['nokp'];
    $homeadd=$_POST['homeadd'];
    $teleoff=$_POST['teleoff'];
    $restele=$_POST['restele'];
    $mobiletele=$_POST['mobiletele'];
    $position=$_POST['position'];
    $grade=$_POST['grade'];
    $serviceduration=$_POST['serviceduration'];
    $mohappt=$_POST['mohappt'];


    $t_t = $_POST["mohappt"];
    $hari=substr("$t_t",0,2); $bulan=substr("$t_t",3,2); $tahun=substr("$t_t",6,4);
    $mohappt="$tahun"."-"."$bulan"."-"."$hari";
    //$mohappt=$_POST['mohappt'];

    $strSQL = "SELECT * FROM peribadi_details WHERE nokp = '".$nokp."'";


    $objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
    $checkavailable = mysqli_fetch_array ($objQuery);

    if($checkavailable==1) {


    $stmt="update peribadi,peribadi_details set namapegawai='$name',nokp=$nokp,homeadd1='$homeadd',officephone='$teleoff',homephone='$restele',mobil ephone='$mobiletele',position='$position',grade=$grade,serviceduration=$serviceduration,mohappointme nt='$mohappt' WHERE peribadi.nokp=peribadi_details.nokp AND peribadi.nokp='$nokp'";


    $objQuery = mysqli_query($conn,$stmt) or die ("Error Query [".$stmt."]");
    $Num_Rows = mysqli_num_rows($objQuery);

    }
    else {

    $a = $_POST['name'];
    $b = $_POST['nokp'];
    $c = $_POST['homeadd'];
    $d = $_POST['teleoff'];
    $e = $_POST['restele'];
    $f = $_POST['mobiletele'];
    $g = $_POST['position'];
    $h = $_POST['grade'];
    $i = $_POST['serviceduration'];
    $j = $_POST['mohappt'];

    $strSQL = "insert into peribadi_details (name,nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)";
    $objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysqli_num_rows($objQuery);

    echo "New records created successfully";

    }
    }


    and the error came out like this

    Error Query [insert into peribadi_details (name,nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES (GURVINDERJEET KAUR A/P SARJIT SINGH,870828565466,selayang,06-303456,727363,0112332143,Consultant,,,21-09-2018)]
      My Computer


  5. Posts : 6
    Windows 10 x64
    Thread Starter
       #5

    still error


    I've changed the coding like this

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name=test_input($_POST['name']);
    $nokp=test_input($_POST['nokp']);
    $homeadd=test_input($_POST['homeadd']);


    $teleoff=test_input($_POST['teleoff']);
    $restele=test_input($_POST['restele']);
    $mobiletele=test_input($_POST['mobiletele']);
    $position=test_input($_POST['position']);
    $grade=test_input($_POST['gred']);
    $serviceduration=test_input($_POST['serviceduration']);
    }


    $name=$_POST['name'];
    $nokp=$_POST['nokp'];
    $homeadd=$_POST['homeadd'];
    $teleoff=$_POST['teleoff'];
    $restele=$_POST['restele'];
    $mobiletele=$_POST['mobiletele'];
    $position=$_POST['position'];
    $grade=$_POST['grade'];
    $serviceduration=$_POST['serviceduration'];
    $mohappt=$_POST['mohappt'];


    $t_t = $_POST["mohappt"];
    $hari=substr("$t_t",0,2); $bulan=substr("$t_t",3,2); $tahun=substr("$t_t",6,4);
    $mohappt="$tahun"."-"."$bulan"."-"."$hari";
    //$mohappt=$_POST['mohappt'];

    $strSQL = "SELECT * FROM peribadi_details WHERE nokp = '".$nokp."'";


    $objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
    $checkavailable = mysqli_fetch_array ($objQuery);

    if($checkavailable==1) {


    $stmt="update peribadi,peribadi_details set namapegawai='$name',nokp=$nokp,homeadd1='$homeadd',officephone='$teleoff',homephone='$restele',mobil ephone='$mobiletele',position='$position',grade=$grade,serviceduration=$serviceduration,mohappointme nt='$mohappt' WHERE peribadi.nokp=peribadi_details.nokp AND peribadi.nokp='$nokp'";


    $objQuery = mysqli_query($conn,$stmt) or die ("Error Query [".$stmt."]");
    $Num_Rows = mysqli_num_rows($objQuery);

    }
    else {

    $a = $_POST['name'];
    $b = $_POST['nokp'];
    $c = $_POST['homeadd'];
    $d = $_POST['teleoff'];
    $e = $_POST['restele'];
    $f = $_POST['mobiletele'];
    $g = $_POST['position'];
    $h = $_POST['grade'];
    $i = $_POST['serviceduration'];
    $j = $_POST['mohappt'];

    $strSQL = "insert into peribadi_details (name,nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)";
    $objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysqli_num_rows($objQuery);


    echo "New records created successfully";

    }
    }

    and the error came out like this

    Error Query [insert into peribadi_details (name,nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES (GURVINDERJEET KAUR A/P SARJIT SINGH,870828565466,selayang,06-303456,727363,0112332143,Consultant,,,21-09-2018)]
      My Computer


  6. Posts : 4,049
    W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
       #6

    Matching Data Types?


    Are you sure that the values you are trying to insert match the data type(s) of the DB table columns/fields?

    For example:

    • Inserting integers into INT fields
    • Strings into TEXT/VARCHAR fields
    • Correct DATE format

    Are you inserting the date as a String or Date?

    From my course notes:
    The format of a DATE value is 'YYYY-MM-DD'.
    According to ANSI SQL, no other format is allowed.
      My Computer


  7. Posts : 6
    Windows 10 x64
    Thread Starter
       #7

    Yes..I'm sure that I inserted the data as format..and the date format I set as Date..but still have this error..
      My Computer


  8. Posts : 4,049
    W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
       #8

    happy memorial said:
    Yes..I'm sure that I inserted the data as format..and the date format I set as Date..but still have this error..
    Your earlier post mentioned this:
    Error Query [insert into peribadi_details (name,nokp,homeadd1,officephone,homephone,mobilephone,position,grade,serviceduration,mohappointment) VALUES (GURVINDERJEET KAUR A/P SARJIT SINGH,870828565466,selayang,06-303456,727363,0112332143,Consultant,,,21-09-2018)
    From my course notes:
    The format of a DATE value is 'YYYY-MM-DD'.
    According to ANSI SQL, no other format is allowed.
    Are you sure that your date is correctly formatted?
    The error message seems to indicate that the date is not correct.
    It should be 2018-09-21.
      My Computer


  9. Posts : 6
    Windows 10 x64
    Thread Starter
       #9

    thanks..I able to manage it now! meow~~
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:34.
Find Us