Author |
Message |
Donovan
Client

Joined: Oct 07, 2003
Posts: 735
Location: Ohio
|
Posted:
Fri Jan 04, 2008 1:22 pm |
|
I have code that checks to see if I have any errors in the StudentID from an imported scantron and if so notifies the user.
Code:
//Check valid Students UID's and compare to the imported table
$checkUID = $db->sql_query("SELECT a.StudentID FROM ".$prefix."_tl_session_grade_import a
LEFT JOIN ".$prefix."_tl_students b ON a.StudentID = b.U_Account
WHERE b.U_Account IS NULL");
|
Then if it finds records it stops.
Code:
$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();
|
if not it proceeds to import the records into the grades table
Code:} else {
//No errors detected so import IRAT grades from _tl_session_grade_import into _tl_session_grades table.
$sql = ("INSERT INTO ".$prefix."_tl_session_grades (Session_ID, SOMS_KEY, UID, Group_ID, IRAT_Grade)
(SELECT a.Session_ID, b.SOMS_KEY, a.StudentID, c.Group_ID, a.Total_Percent FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b ON (a.StudentID = b.U_Account)
JOIN ".$prefix."_tl_group_students c ON (b.SOMS_KEY = c.SOMS_KEY)
JOIN ".$prefix."_tl_session d
WHERE a.Session_ID = d.Session_ID)");
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
|
I know I have approx five records that are mismatched a.StudentID = b.U_Account, but the page send me to
Code:
header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");
|
without any notification of errors or inserting the data.
TLViewIratGrades displays nothing as the tl_session_grades table is still empty.
I could have sworn this was working before I went on break for the holidays.  |
|
|
 |
 |
fkelly
Former Moderator in Good Standing

Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Fri Jan 04, 2008 3:15 pm |
|
You don't show where in your code you are setting that header. I've found that setting headers like that can be very tricky because if it gets executed in the normal flow of things you wind up going right to the header location despite what the rest of your program is trying to do. You might try having a form just for that situation where there are no records found and setting the action to admin.file with the op you have already set. And of course you'd need that op in the case file for your module.
Setting headers like that can also disrupt your attempts to echo out diagnostics in your program. Before the echo ever takes place the program gets redirected. |
|
|
|
 |
Donovan

|
Posted:
Fri Jan 04, 2008 4:36 pm |
|
It's at the very end
Code:
$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.
$sql = ("INSERT INTO ".$prefix."_tl_session_grades (Session_ID, SOMS_KEY, UID, Group_ID, IRAT_Grade)
(SELECT a.Session_ID, b.SOMS_KEY, a.StudentID, c.Group_ID, a.Total_Percent FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b ON (a.StudentID = b.U_Account)
JOIN ".$prefix."_tl_group_students c ON (b.SOMS_KEY = c.SOMS_KEY)
JOIN ".$prefix."_tl_session d
WHERE a.Session_ID = d.Session_ID)");
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
}
header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");
?>
|
|
|
|
|
 |
fkelly

|
Posted:
Fri Jan 04, 2008 6:25 pm |
|
and I think that by being outside the else it is executing in all cases and redirecting you without giving the rest of your logic a chance to work. Try commenting that out or just putting an echo in its place that says "I would have done a header here".
there are others here who know PHP much better than I do, and FB uses Header redirects liberally throughout NUKE, but I just kind of shy away from them now whenever I can avoid them. |
|
|
|
 |
Gremmie
Former Moderator in Good Standing

Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Fri Jan 04, 2008 6:26 pm |
|
When debugging code that contains header() calls, I sometimes will search and replace them all to be die(). |
_________________ Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module |
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Fri Jan 04, 2008 6:55 pm |
|
You must always use a die() or exit() statement to avoid the header() from executing. Your code needs to readCode:
$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();
die();
} else {
//No errors detected so import IRAT grades from _tl_session_grade_import into _tl_session_grades table.
$sql = ("INSERT INTO ".$prefix."_tl_session_grades (Session_ID, SOMS_KEY, UID, Group_ID, IRAT_Grade)
(SELECT a.Session_ID, b.SOMS_KEY, a.StudentID, c.Group_ID, a.Total_Percent FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b ON (a.StudentID = b.U_Account)
JOIN ".$prefix."_tl_group_students c ON (b.SOMS_KEY = c.SOMS_KEY)
JOIN ".$prefix."_tl_session d
WHERE a.Session_ID = d.Session_ID)");
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");
die();
}
}
header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");
?>
|
|
|
|
|
 |
Donovan

|
Posted:
Mon Jan 07, 2008 3:17 pm |
|
|
|
 |
|