Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $response['success'] = array('success' => false, 'messages' => array());
- $Id = trim(intval($_POST['id']));
- $name = strip_tags(trim(strval($_POST['name'])));
- $age = strip_tags(trim(strval($_POST['age'])));
- $gender = strip_tags(trim(strval($_POST['gender'])));
- $data = array();
- if(count($_POST['data']) > 0){
- foreach($_POST['data'] as $key => $array){
- $row = array();
- $row['subject_id'] = intval($array['subject_id']);
- $data[$key] = $row;
- }
- }
- try{
- $query1 = "insert into students (name,age,gender) values(:name,:age,:gender)";
- $query1 = $con->prepare($query1);
- $query1->bindparam(':name',$p_name);
- $query1->bindparam(':age',$age);
- $query1->bindparam(':gender',$gender);
- $run_query1 = $query1->execute();
- foreach($data as $key => $array){
- $check_multiple = $db->prepare("SELECT * From subjects WHERE subject_id = :subject_id ");
- $check_multiple->execute(array(':subject_id' => $array['subject_id']));
- $count = $check_multiple->rowCount();
- if($count > 0) {
- while($row1 = $check_multiple->fetch(PDO:: FETCH_ASSOC) ) {
- $subject_id = $row1['subject_id'];
- $subject = $row1['subject'];
- $part_name = $row1['part'];
- $query2 = $db->prepare("INSERT INTO results (student_id,subject_id,subject,part) values(:student_id,:subject_id,:subject,:part)");
- $query2->bindparam(':student_id', $student_id);
- $query2->bindparam(':subject_id', $subject_id);
- $query2->bindparam(':subject', $subject);
- $query2->bindparam(':part', $part);
- $query2->execute();
- }
- }
- }
- if (!$run_query1 && !$query2){
- $result['success'] = false;
- $result['messages'] = "Error";
- } else {
- $result['success'] = true;
- $result['messages'] = "Success";
- }
- }
- catch(PDOException $e){
- echo 'Connection failed: ' . $e->getMessage();
- }
- echo json_encode($result);
- ?>
Add Comment
Please, Sign In to add comment