Donovan Posted January 7, 2008 Share Posted January 7, 2008 This bit of code is not working in my script. //Drop Import table $sql = "DROP TABLE IF EXISTS ".$prefix."_tl_session_grade_import"; $result = $db->sql_query($sql); if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} I do not get any $results echoed for any mysql_error(), and the table _tl_session_grade_import does not get dropped. Here is the code in it's entirety. <?php if(!defined('TL_ADMIN')) { die("Illegal Access Detected!!!"); } global $prefix; $modname = "Team_Learning"; include("header.php"); TLAdminMenu(); $Session_ID = $_POST['Session_ID']; /* //Check if already imported $checkSession = $db->sql_query("SELECT * FROM ".$prefix."_tl_session_grades WHERE Session_ID = '$Session_ID' AND IRAT_Grade != 0"); $Session_total = $db->sql_numrows($checkSession); //We have Session_ID's for IRAT's that have already been imported. if ($Session_total > 0) { OpenTable(); echo"<tr><td>IRAT grades for this Session have already been imported.</td></tr>"; echo"<tr><td>You can edit individual IRAT grades <a href='".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID'>Here!</a></td></tr>"; Closetable(); exit(); } */ //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 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"); //AND a.Session_ID = '$Session_ID'"); //WHERE 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. $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>");} //Get the academic year and update table $Get_Academic_Year = $db->sql_query("UPDATE ".$prefix."_tl_session_grades SET Academic_Year = (SELECT Academic_Year FROM ".$prefix."_tl_config)"); //Drop Import table $sql = "DROP TABLE IF EXISTS ".$prefix."_tl_session_grade_import"; $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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84871-drop-table-if-exists/ Share on other sites More sharing options...
duclet Posted January 7, 2008 Share Posted January 7, 2008 Try echoing that $sql variable after it is being declared to see if your SQL is correct since there is a chance that the $prefix might be empty. Quote Link to comment https://forums.phpfreaks.com/topic/84871-drop-table-if-exists/#findComment-432671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.