I'm trying to make a class registration page, but for some reason, when I dump my query results into an array and use array_search on it, array_search comes up null. Any ideas?
<?php
/* - if classes[] is set, see if any of them were selected
- if yes, insert the class into the grades table with the student's GWid and grade of IP(in progress).
if the course was already in the grades table with an NG grade, change the grade to IP.
- if no, do nothing
- if it is not set, do nothing
*/
$nextterm = $_SESSION['nextterm'];
if($nextterm == 'spring')
{
$termyear = (date('Y') + 1);
}
else
{
$termyear = date('Y');
}
if(isset($_POST['classes']))
{
$sql = "SELECT classid FROM grades WHERE GWid=$GWid AND grade='NG'";
$result = mysql_query($sql);
if(!$result)
{
die("Error querying database:" . mysql_error());
}
list($ngclasses) = mysql_fetch_array($result);
foreach($_POST['classes'] as $key => $cid)//for every class that gets posted:
{
/*****************************************************************
******** Issue starts here *********************************
******************************************************************
*/
if(array_search($cid, $ngclasses))//this comes up null
{//change NG grade to IP
$sql = "UPDATE grades SET grade='IP' WHERE GWid=$GWid AND classid='$cid'";
}
else
{//insert class into grade table with in progress grade (IP)
$sql = "INSERT INTO grades(GWid, classid, grade, semester, year, required) VALUES("
. $_SESSION['GWid'] . ", '$cid', 'IP', '$nextterm', '$termyear', 'no')";
}
$result = mysql_query($sql);
if(!$result)
{
die("Error querying database:" . mysql_error());
}
}
/*$result = mysql_query($sql);
if(!$result)
{
die("Error querying database:" . mysql_error());
}
*/
header("Location: viewsched.php");
}
?>