PHP - function not returning value inside isset -
i have function call find_student_by_id() 1 arg complete code below.
function find_student_by_id($student_number){ global $con; $safe_student_number = prep($student_number); $sql = "select * "; $sql .= "from studeprofile "; $sql .= "where studentnumber = '{$safe_student_number}'"; $sql .= "limit 1"; $student_set = mysqli_query($con, $sql); confirm_query($student_set); if($student = mysqli_fetch_assoc($student_set)){ return $student; } else { return null; } } this function work fine if call anywhere in page, if use inside isset function not returning value.
$student = find_student_by_id('id-201'); if use outside isset give me value echo $student['student_number'];
but if used inside isset no value return.
if(isset($_post['submit'])){ $student_number = $student['student_number']; } complete code inside cor.php
<?php $student = find_student_by_id($_get['student_number']); //if(!$student){ // redirect_to('home.php'); //} //$_session['sn'] = $student['studentnumber']; ?> <?php if(isset($_get['subject_id'])){ $subject = find_subject_id($_get['subject_id']); } //if(!$subject){ // redirect_to('cor.php'); //} ?> <?php if(isset($_post['submit'])){ $subject_code = $subject['subjectcode']; $description = $subject['description']; $lec_unit = ""; $lab_unit = ""; $section = ""; $labtime = ""; $sched_time = ""; $room = ""; $instructor = ""; $sem = ""; $sy = ""; $sn = $student['studentnumber']; $term = ""; $fn = $student['firstname']; $mn = $student['middlename']; $ln = $student['lastname']; $course = $student['course']; $yl = $student['yearlevel']; $sql = "insert registration("; $sql .= "subjectcode, description, lecunit, labunit, "; $sql .= "section, labtime, schedtime, room, instructor, "; $sql .= "sem, sy, studentnumber, term, firstname, middlename, "; $sql .= "lastname, course, yearlevel"; $sql .= ")values("; $sql .= "'{$subject_code}', '{$description}', '{$lec_unit}', '{$lab_unit}', '{$section}', '{$labtime}', "; $sql .= "'{$sched_time}', '{$room}', '{$instructor}', '{$sem}', '{$sy}', '{$sn}', "; $sql .= "'{$term}', '{$fn}', '{$mn}', '{$ln}', '{$course}', '{$yl}'"; $sql .= ")"; $cor = mysqli_query($con, $sql); if($cor){ redirect_to('cor.php?student_number='.$subject_code); } else { die(mysqli_error($con)); } } ?> <div> student number : <?php echo $student['studentnumber']; ?><br /> name: <?php echo fullname($student); ?> <a class="popup" href="search-subject-cor.php">add subject</a> <br /> <br /> <p><?php echo $subject['subjectcode']; ?></p> <p><?php echo $subject['description']; ?></p> <form method="post" action="cor.php"> <input type="submit" name="submit" value="add subject" /> </form>
if(isset($_get['subject_id'])){ ^ $subject = find_subject_id($_get['subject_id']); } compare with
<form method="post" action="cor.php"> ^ and delete question :)
Comments
Post a Comment