Jump to content

INSERT INTO errors.


Donovan

Recommended Posts

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();  
}     

Link to comment
Share on other sites

Does your sql_query method actually return true or false? Your error handling code doesn't seem to be getting called.

 

Try replacing...

 

$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>");}  
}

 

with...

 

$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')");
die(mysql_error());

 

and lets see if we can get an error message.

Link to comment
Share on other sites

No error message.

 

 

I also ran this in phpMyadmin to see how many results I had.  it came back with 104 records which is correct.

 

SELECT b.SOMS_KEY, b.U_Account, a.Total_Percent, a.Session_ID FROM atlas_tl_session_grade_import a
JOIN atlas_tl_students b
ON (a.StudentID = b.U_Account)
AND a.Session_ID = '8'

 

It returned 104 records of

 

 

SOMS_KEY

U_Account

Total_Percent

Session_ID

 

I previously defined $Grade_Type = 'IRAT';

 

as well as getting the $Academic_Year = $info['Academic_Year'];

 

Link to comment
Share on other sites

 

In my table ".$prefix."_tl_session_grades

 

I also have Group_ID which is a variable that will hold ID's from Group's when the Grade_Type is GRAT instead of IRAT.

 

GRAT stands for Group Readiness Assessment Test, and IRAT stands for Individual Readiness Assessment Test

 

Group_ID is datatype int(11) and NULL is Yes, since not all records will be Group records, but individual records, of course depending on what type of grade it is.

 

 

...Savvy?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.