Di sql sudah bisa tapi di php tidak bisa

saya membuat alter table DI SQL Tidak ada masalah. tapi ketika saya membuat inputan pada program web masih terjadi Integrity constraint violation

pada table Siswa

CREATE TABLE `tb_siswa` (
  `programid` int(5) NOT NULL,
  `jobid` int(5) NOT NULL,
  `classid` int(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `tb_siswa`
  ADD CONSTRAINT `class` FOREIGN KEY (`classid`) REFERENCES `class` (`idclass`),
  ADD CONSTRAINT `job` FOREIGN KEY (`jobid`) REFERENCES `job` (`idjob`),
  ADD CONSTRAINT `program` FOREIGN KEY (`programid`) REFERENCES `program` (`idprogram`);
COMMIT;

pada table Program

CREATE TABLE `program` (
  `idprogram` int(5) NOT NULL,
  `programname` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

pada Table Job

CREATE TABLE `job` (
  `idjob` int(5) NOT NULL,
  `jobname` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Pada Table Class

CREATE TABLE `class` (
  `idclass` int(5) NOT NULL,
  `classname` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

<?php

require_once "connection.php";

//Ambil data dari database
$sql="SELECT * FROM program";
$sql2="SELECT * FROM class";
$sql3="SELECT * FROM job";

try{

	$stmt=$db->prepare($sql);
	$stmt2=$db->prepare($sql2);
	$stmt3=$db->prepare($sql3);

	$stmt->execute();
	$program=$stmt->fetchAll();
	$stmt2->execute();
	$class=$stmt2->fetchAll();
	$stmt3->execute();
	$job=$stmt3->fetchAll();
}
catch (PDOException $exc){

	echo ($exc->getMassage());
}
//end ambil data

if(isset($_POST['btn_insert'])){
	try
	{
	$namasiswa	= $_POST['txt_namasiswa'];	//textbox name "txt_firstname"
	$tempatlahir	= $_POST['txt_tempatlahir'];	//textbox name "txt_lastname"
	$tgllahir	= $_POST['tanggal'];
	$jenkel	= $_POST['gender'];
	$berat = $_POST['txt_berat'];
	$tinggi = $_POST['txt_tinggi'];
	$tinggi = $_POST['txt_tinggi'];
	$hslagama = $_POST['txt_agama'];
	$negara = $_POST['txt_negara'];
	$marital = $_POST['marital'];
	$address = $_POST['txt_address'];
	$hpsiswa = $_POST['txt_hpsiswa'];
	$telpsiswa = $_POST['txt_telpsiswa'];
	$email = $_POST['txt_email'];
	$study = $_POST['study'];
	$sekolah = $_POST['txt_sekolah'];
	$alamatsekolah = $_POST['txt_alamatsekolah'];
	$family = $_POST['family'];
	$familyname = $_POST['txt_familyname'];
	$alamatfamily = $_POST['txt_alamatortu'];
	$hportu = $_REQUEST['txt_hportu'];
	$tlportu = $_REQUEST['txt_tortu'];
	$experience = $_REQUEST['txt_experience'];
	$perusahaan = $_REQUEST['txt_perusahaan'];
	$mulai = $_REQUEST['txt_start'];
	$akhir = $_REQUEST['txt_akhir'];
	$namaref = $_REQUEST['txt_namaref'];
	$hasilprogram = $_POST['selectprogram'];
	$hasilclass = $_POST['selectclass'];
	$hasiljob = $_POST['selectjob'];

	$image_file = $_FILES["images"]["name"];
	$type  = $_FILES["images"]["type"]; //file name "txt_file"
	$size  = $_FILES["images"]["size"];
	$temp  = $_FILES["images"]["tmp_name"];

	$path="upload/".$image_file; //set upload folder path

	if(empty($namasiswa)){
		$errorMsg="Please Enter Class Code";
	}
	else if(empty($tempatlahir)){
		$errorMsg="Please Enter Place of Birth";
	}
	else if(empty($tgllahir)){
		$errorMsg="Please Enter Date of Birth";
	}
	else if(empty($jenkel)){
		$errorMsg="Please Enter Gender";
	}
	else if(empty($berat)){
		$errorMsg="Please Enter Weight";
	}
	else if(empty($tinggi)){
		$errorMsg="Please Enter Height";
	}
	else if(empty($hslagama)){
		$errorMsg="Please Enter Religion";
	}
	else if(empty($negara)){
		$errorMsg="Please Enter Nationality";
	}
	else if(empty($marital)){
		$errorMsg="Please Enter Marital";
	}
	else if(empty($hpsiswa)){
		$errorMsg="Please Enter Handphone Number";
	}
	else if(empty($email)){
		$errorMsg="Please Enter Email";
	}
	else if(empty($image_file)){
		$errorMsg="Please Select Image";
	}
		else if($type=="image/jpg" || $type=='image/jpeg' || $type=='image/png' || $type=='image/gif') //check file extension
	{
		if(!file_exists($path)) //check file not exist in your upload folder path
		{
	   if($size < 5000000) //check file size 5MB
	   {
		move_uploaded_file($temp, "upload/" .$image_file); //move upload file temperory directory to your upload folder
	   }
	   else
	   {
		$errorMsg="Your File To large Please Upload 5MB Size"; //error message file size not large than 5MB
	   }
	  }
	  else
	  {
	   $errorMsg="File Already Exists...Check Upload Folder"; //error message file not exists your upload folder path
	  }
	 }
	 else
	 {
	  $errorMsg="Upload JPG , JPEG , PNG & GIF File Formate.....CHECK FILE EXTENSION"; //error message file extension
	 }

	 if(!isset($errorMsg))
	 {
		$insert_stmt=$db->prepare('INSERT INTO tb_siswa(nama_siswa, tempat_lhr, tgl_lhr, jen_kel, berat_bdn, tinggi_bdn, religion, kebangsaan, status_nikah, alamatsiswa, hpsiswa, telsiswa, emailsiswa, pendidikan, nama_sklh, alamat_sklh, family, familyname, alamat_ortu, hp_ortu, tlp_ortu, job_position, nm_perusahaan, tgl_start, tgl_end, nama_ref, programid, jobid, classid, foto) VALUES( :namasiswa, :tempatlahir, :tgllahir, :jenkel, :bb, :tb, :hslagama, :negara, :marital, :alamat, :hapesiswa, :telpsiswa, :email, :study, :namasekolah, :alamatsekolah, :families, :familyname, :alamatortu, :hportu, :telportu, :experience, :perusahaan, :mulai, :akhir, :namaref, :pprogram, :jjob, :cclass, :images)'); //sql insert query
		$insert_stmt->bindParam(':namasiswa',$namasiswa);
		$insert_stmt->bindParam(':tempatlahir',$tempatlahir);   //bind all parameter
		$insert_stmt->bindParam(':tgllahir',$tgllahir);
		$insert_stmt->bindParam(':jenkel',$jenkel);
		$insert_stmt->bindParam(':bb',$berat);
		$insert_stmt->bindParam(':tb',$tinggi);
		$insert_stmt->bindParam(':hslagama',$hslagama);
		$insert_stmt->bindParam(':negara',$negara);
		$insert_stmt->bindParam(':marital',$marital);
		$insert_stmt->bindParam(':alamat', $address);
		$insert_stmt->bindParam(':hapesiswa', $hpsiswa);
		$insert_stmt->bindParam(':telpsiswa', $telpsiswa);
		$insert_stmt->bindParam(':email', $email);
		$insert_stmt->bindParam(':study', $study);
		$insert_stmt->bindParam(':namasekolah', $sekolah);
		$insert_stmt->bindParam(':alamatsekolah', $alamatsekolah);
		$insert_stmt->bindParam(':families', $family);
		$insert_stmt->bindParam(':familyname', $familyname);
		$insert_stmt->bindParam(':alamatortu', $alamatfamily);
		$insert_stmt->bindParam(':hportu', $hportu);
		$insert_stmt->bindParam(':telportu', $tlportu);
		$insert_stmt->bindParam(':experience', $experience);
		$insert_stmt->bindParam(':perusahaan', $perusahaan);
		$insert_stmt->bindParam(':mulai', $mulai);
		$insert_stmt->bindParam(':akhir', $akhir);
		$insert_stmt->bindParam(':namaref', $namaref);
		$insert_stmt->bindParam(':pprogram', $hasilprogram);
		$insert_stmt->bindParam(':jjob', $hasiljob);
		$insert_stmt->bindParam(':cclass', $hasilclass);
		$insert_stmt->bindParam(':images', $image_file);

		if($insert_stmt->execute())
	  		{
	  		 $insertMsg="REGISTER SUCCESFULLY"; //execute query success message
	  		 header("refresh:3;index_user.php"); //refresh 3 second and redirect to index.php page
	  		}
	 	}
	}
	catch(PDOException $e)
	{
	 echo $e->getMessage();
	}
}

				<div class="form-group">
							<label class="col-sm-3 control-label">Select Program</label>
							<div class="col-sm-6">
								<select name="selectprogram" class="form-control" id="selectprogram" required>
								<option value="">- Select Program -</option>
								<?php foreach ($program as $output) {?>
								<option value="<?php echo ['idprogram']; ?>"><?php echo $output['programname']; ?></option>
								<?php } ?>
    						</select>
							</div>
				</div>

				<div class="form-group">
							<label class="col-sm-3 control-label">Select Job</label>
							<div class="col-sm-6">
								<select name="selectjob" class="form-control" id="selectjob" required>
								<option value="">- Select Job Position -</option>
								<?php foreach ($job as $output) {?>
								<option value="<?php echo ['idjob']; ?>"><?php echo $output['jobname']; ?></option>
								<?php } ?>
    						</select>
							</div>
				</div>

				<div class="form-group">
							<label class="col-sm-3 control-label">Select Class</label>
							<div class="col-sm-6">
								<select name="selectclass" class="form-control" id="selectclass" required>
								<option value="">- Select Class -</option>
								<?php foreach ($class as $output) {?>
								<option value="<?php echo ['idclass']; ?>"><?php echo $output['classname']; ?></option>
								<?php } ?>
    						</select>
							</div>
				</div>

apakah masih ada yang blm sesuai? atau saya berikut tampilan errornya dan di sql

mohon bantuannya

avatar faqih996
@faqih996

5 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban