function store_data_in_db($params) { $db = get_db_handle(); $sql = "select * from parent where first_name='{$params['0']}' and secondary_phone='{$params['36']}' and email='{$params['15']}';"; $result = mysqli_query($db, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $parent_id = $row[0]; $sql = "select * from child where parent_id='{$parent_id}' and first_name='{$params['16']}' and birthdate='{$params['22']}' ;"; //echo "parent_id".$parent_id; $result = mysqli_query($db, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $child_id = $row[0]; $enrollment = 0; $program = camps($params); for ($i = 0; $i < count($program); $i++) { $sql = "select * from enrollment where program_id='{$program[$i]}' and child_id='{$child_id}';"; $result = mysqli_query($db, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $enrollment = 1; } } if ($enrollment == 1) { write_error_page('The child is already registered for the program selected.Click<a href="Enrollment.html"> here </a> to go back to the previous screen'); exit; } else { insert_enrollment($child_id, $params, $db); } } else { insert_child($parent_id, $params, $db); } } else { ### NOT A DUP // $sql = "Insert into parent(first_name,middle_name,last_name,address1,address2,city,state,zip,primary_phone,secondary_phone,email) values ('sdsasdf','sdasdfssa','dsd','asasdfda','dsad','fsdfs','CA',91110,2222222222,1111122222,'*****@*****.**')"; // echo "'".$params[0]."'<br>"; // echo "'".$params[1]."'<br>"; // echo "'".$params[2]."'<br>"; // echo "'".$params[3]."'<br>"; // echo "'".$params[4]."'<br>"; // echo "'".$params[5]."'<br>"; // echo "'".$params[6]."'<br>"; // echo "'".$params[7]."'<br>"; // echo "'".$params[35]."'<br>"; // echo "'".$params[36]."'<br>"; // echo "'".$params[15]."'<br>"; $sql = "insert into parent(first_name,middle_name,last_name,address1,address2,city,state,zip,primary_phone,secondary_phone,email) " . "values('{$params['0']}','{$params['1']}','{$params['2']}','{$params['4']}','{$params['5']}','{$params['6']}','{$params['7']}','{$params['8']}','{$params['35']}','{$params['36']}','{$params['15']}');"; // if(mysqli_query($db,$sql)===True) echo "success"; // else echo "No Donut"; mysqli_query($db, $sql); //$how_many = mysqli_affected_rows($db); $parent_id = mysqli_insert_id($db); //echo "parent_id in else".$parent_id; if (!empty($parent_id)) { insert_child($parent_id, $params, $db); } else { echo "A critical error occurred."; } } mysqli_close($db); }
$sql = "select id from child where parent_id='{$parent_id}' and first_name='{$cname}';"; $result = mysqli_query($db, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $child_id = $row[0]; } $enrollment = 0; //global $bad_chars; $params = array(); $params[] = trim(str_replace($bad_chars, "", $_POST['basketball'])); $params[] = trim(str_replace($bad_chars, "", $_POST['baseball'])); $params[] = trim(str_replace($bad_chars, "", $_POST['training'])); $params[] = trim(str_replace($bad_chars, "", $_POST['band'])); $params[] = trim(str_replace($bad_chars, "", $_POST['swimming'])); $params[] = trim(str_replace($bad_chars, "", $_POST['nature'])); $program = camps($params); for ($i = 0; $i < count($program); $i++) { $sql = "select * from enrollment where program_id='{$program[$i]}' and child_id='{$child_id}';"; $result = mysqli_query($db, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $enrollment = 1; } } if ($parent_id && $child_id && $enrollment) { echo "DUP"; } else { echo "OK"; } ?>