I am inserting array data in database through ajax. Insertion of data succeeded without implementing any condition. When I try to implement if condition, it doesn't work. What is error in following code
<?php
include "connect.php";
$class_id = $_POST['class_id'];
$section_name = $_POST['section_name'];
$section_name = implode(",",$section_name);
$query=$con->query("SELECT * FROM section") or die($con->error);
while($row=$query->fetch(PDO::FETCH_ASSOC)){
if(($class_id==$row['class_id'])&&($section_name==$row['section_name'])){
echo json_encode('Section -'.$section_name.' has already assigned in '.$class_id);
}
else{
$query2=$con->query("INSERT INTO section(class_id,section_name) VALUES('$class_id','$section_name')") or die($con->error);
echo json_encode($section_name);
}
}
?>
Aucun commentaire:
Enregistrer un commentaire