I am trying to import data from a scantron. The import goes fine, I cleanse the data afterwords and then if there are no errors I INSERT INTO, but this so far is not working.
I have looked at this for 3 days straight and can't find my error.
I pass the Session_ID in from the url, and have tested that it is available. I have also echoed out the $Academic_Year.
I am not getting any results from this
if (!$sql) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
...so it is hard to find out why this wont work. Any help is appreciated.
$Session_ID = $_GET['Session_ID'];
//Get the academic year
$Get_Academic_Year = $db->sql_query("SELECT Academic_Year FROM ".$prefix."_tl_config");
while ($info = $db->sql_fetchrow($Get_Academic_Year)) {
$Academic_Year = $info['Academic_Year'];
}
//Check the Students UID and compare to the imported table. They all need to match to continue.
$checkUID = $db->sql_query("SELECT a.StudentID, b.U_Account FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b
WHERE a.StudentID != b.U_Account
AND a.Session_ID = '$Session_ID'");
$error_total = $db->sql_numrows($checkUID);
//We have unmatched UID's!
if ($error_total > 0) {
OpenTable();
echo"<tr><td>There are errors in the IRAT imported table. These need to be fixed before writing to the grades table. Ensure all student UID's match for all current students already in the system.</td></tr>";
echo"<tr><td><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></td></tr>";
Closetable();
} else {
//No errors detected so import IRAT grades from _tl_session_grade_import into _tl_session_grades table.
$Grade_Type = 'IRAT';
$getallinfo = $db->sql_query("SELECT b.SOMS_KEY, b.U_Account, a.Total_Percent, a.Session_ID FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b
ON (a.StudentID = b.U_Account)
AND a.Session_ID = '$Session_ID'");
if (!$getallinfo) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
while ($row = $db->sql_fetchrow($getallinfo)) {
$SOMS_KEY = $row['SOMS_KEY'];
$Session_ID = $row['Session_ID'];
$UID = $row['U_Account'];
$Grade = $row['Total_Percent'];
$sql = $db->sql_query("INSERT INTO ".$prefix."_tl_session_grades (Session_ID, SOMS_KEY, UID, Grade, Grade_Type, Academic_Year)". "VALUES ('$Session_ID', '$SOMS_KEY', '$UID', '$Grade', '$Grade_Type', '$Academic_Year')");
if (!$sql) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
}
//Get total count of imported data
$import_total = $db->sql_numrows($sql);
Opentable();
echo"<tr><td>$import_total Grades Added</td></tr>";
CloseTable();
}
I also ran this in phpMyadmin to see how many results I had. it came back with 104 records which is correct.
I previously defined
$Grade_Type = 'IRAT';
as well as getting the
$Academic_Year = $info['Academic_Year'];
So I don't understand why my INSERT INTO is not working.
The only thing that is displayed is