Solved Error Query in PHP

happy memorial

New member
Local time
10:13 AM
Messages
6
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_doc) 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:cry:
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 10 x64
Antivirus
Avast
Weird

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

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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
n/a
OS
W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
CPU
AMD Phenom II x6 1100T, 3.3 GHz
Motherboard
ASUS M4A88T-M/USB3 (AM3)
Memory
12GB DDR3 1333 G-Skill (4GB x 2), G-Skill (2GB x 2)
Graphics Card(s)
NVIDIA GeForce GTX 660
Sound Card
Realtek?
Monitor(s) Displays
Samsung S23B350
Screen Resolution
1920x1080
Hard Drives
WD Green 2TB (SATA), WD Green 3TB (SATA), WD Blue 4TB (SATA), WD Blue 6TB (SATA)
PSU
Cooler Master
Case
Antec GX300 Tower
Cooling
3x Antec TRICOOL 120mm Fans
Mouse
Wired Optical
Internet Speed
DSL
Antivirus
Avast
Browser
Pale Moon (64 bit)
Other Info
2018-12-27 Upgraded HDDs
2015-12-10 Upgraded case, graphics card, storage
2015-08-15 Upgraded motherboard & RAM
2015-07-15 Upgraded LM17.1 to LM17.2
Hi happy memorial, is there any additional information that you could give us that might help?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
I've changes the coding like this:huh:

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',mobilephone='$mobiletele',position='$position',grade=$grade,serviceduration=$serviceduration,mohappointment='$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 :confused:

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

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 10 x64
Antivirus
Avast
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',mobilephone='$mobiletele',position='$position',grade=$grade,serviceduration=$serviceduration,mohappointment='$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

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 10 x64
Antivirus
Avast
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
n/a
OS
W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
CPU
AMD Phenom II x6 1100T, 3.3 GHz
Motherboard
ASUS M4A88T-M/USB3 (AM3)
Memory
12GB DDR3 1333 G-Skill (4GB x 2), G-Skill (2GB x 2)
Graphics Card(s)
NVIDIA GeForce GTX 660
Sound Card
Realtek?
Monitor(s) Displays
Samsung S23B350
Screen Resolution
1920x1080
Hard Drives
WD Green 2TB (SATA), WD Green 3TB (SATA), WD Blue 4TB (SATA), WD Blue 6TB (SATA)
PSU
Cooler Master
Case
Antec GX300 Tower
Cooling
3x Antec TRICOOL 120mm Fans
Mouse
Wired Optical
Internet Speed
DSL
Antivirus
Avast
Browser
Pale Moon (64 bit)
Other Info
2018-12-27 Upgraded HDDs
2015-12-10 Upgraded case, graphics card, storage
2015-08-15 Upgraded motherboard & RAM
2015-07-15 Upgraded LM17.1 to LM17.2
Yes..I'm sure that I inserted the data as format..and the date format I set as Date..but still have this error..:cry:
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 10 x64
Antivirus
Avast
Yes..I'm sure that I inserted the data as format..and the date format I set as Date..but still have this error..:cry:
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
n/a
OS
W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
CPU
AMD Phenom II x6 1100T, 3.3 GHz
Motherboard
ASUS M4A88T-M/USB3 (AM3)
Memory
12GB DDR3 1333 G-Skill (4GB x 2), G-Skill (2GB x 2)
Graphics Card(s)
NVIDIA GeForce GTX 660
Sound Card
Realtek?
Monitor(s) Displays
Samsung S23B350
Screen Resolution
1920x1080
Hard Drives
WD Green 2TB (SATA), WD Green 3TB (SATA), WD Blue 4TB (SATA), WD Blue 6TB (SATA)
PSU
Cooler Master
Case
Antec GX300 Tower
Cooling
3x Antec TRICOOL 120mm Fans
Mouse
Wired Optical
Internet Speed
DSL
Antivirus
Avast
Browser
Pale Moon (64 bit)
Other Info
2018-12-27 Upgraded HDDs
2015-12-10 Upgraded case, graphics card, storage
2015-08-15 Upgraded motherboard & RAM
2015-07-15 Upgraded LM17.1 to LM17.2
thanks..I able to manage it now! meow~~
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 10 x64
Antivirus
Avast
Back
Top