Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Mon Jan 07, 2008 3:25 pm Reply with quote

I have a script that is currently not working. I have done several searches but can't figure this out.

I have a table _tl_session_grades I am trying to update records in. It already contains data for the Session_ID, SOMS_KEY, UID , Group_ID, IRAT_Grade and Academic_Year.

Code:
Session_ID      int(11)  

SOMS_KEY     int(11)    
UID     varchar(9)    
Group_ID     int(11)    
IRAT_Grade     int(4)         
GRAT_Grade     int(4)          
AppEx_Grade     int(4)              
Academic_Year     varchar(5)


I need to update the GRAT_Grade. I have about 16 Groups (Group_ID) that I have a form for and place a grade into a text box.

Code:


echo "<form method='post' action='".$admin_file.".php'>\n";
echo "<input type='hidden' name='op' value='TLSessionGratGradesInsert'>\n";
echo "<table width='100%' border='1' cellspacing='0' cellpadding='2'>\n";
echo "<tr><td colspan='3' width='100%' bgcolor='$bgcolor2'><nobr><b>TL GRAT Session Name: $Session_Name for Course $Course_Name</b></nobr></td></tr>\n";
echo "<tr><td colspan=2 width='100%'><nobr>Year $Course_Year Groups</td></tr>\n";
echo "</table>\n";
echo "<br />\n";
echo "<table width='100%' align='center' border='1' cellspacing='0' cellpadding='2'>\n";
echo "<tr><td align='center' bgcolor='$bgcolor2' width='5%'><b>Group ID</b></td><td align='left' bgcolor='$bgcolor2' width='50%'><b>Group Name</b></td><td align ='center' bgcolor='$bgcolor2' width='20%'><b>GRAT Grade</b></td></tr>\n";
$groupYearlist = $db->sql_query("SELECT * FROM ".$prefix."_tl_groups WHERE Group_Year = $Course_Year");
while ($row = $db->sql_fetchrow($groupYearlist)) {
      $Group_ID = $row['Group_ID'];
      $Group_Name = $row['Group_Name'];      
      
      if (!$groupYearlist) {
      echo("<p>Error performing query: " . mysql_error() . "</p>");
      exit();   
      }   

  //<!-- BEGIN Group Row -->"
   echo "<tr><td align=\"center\">$Group_ID</td>" 
  . " <td align=\"left\">$Group_Name</td>" 
  . " <td><input type='text' name='GRAT_Grade[{$Group_ID}]' size='3' maxlength='3'></td>"
  . "</tr>";   
  }
  //-- END Group Row -->"
 echo "<tr><td colspan='3' align='center'><input type='submit' value='Add Grade(s)'></td></tr>\n";
 echo "</form>\n";
 echo "</table>\n";


Here is the relevant code from the TLSessionGratGradesInsert page.
Code:


$Session_ID = $_POST['Session_ID'];
$Group_ID = $_POST['Group_ID'];   
foreach($_POST['GRAT_Grade'] as $key => $value) {
      $sql = $db->sql_query("UPDATE ".$prefix."_tl_session_grades SET GRAT_Grade = '$GRAT_Grade' WHERE Group_ID = '$Group_ID' AND Session_ID = '$Session_ID'") or die('Error, query failed. ' . mysql_error());
   }


I placed this to see what my POST contained:

Code:
echo '<pre style="text-align: left;">' . print_r($_POST, true) . '</pre>';


I am now getting this:

Code:
Array

(
    [op] => TLSessionGratGradesInsert
    [GRAT_Grade] => Array
        (
            [1] => 90
            [4] => 90
            [7] => 80
            [8] => 70
            [9] => 95
            [10] => 85
            [11] => 90
            [12] => 100
            [13] => 100
            [14] => 90
            [15] => 80
            [16] => 70
        )

    [Session_ID] => 43
)


Which is correct. Each Group_ID has its corrosponding GRAT_Grade

But I am having trouble updating the table.

If $Key is the Group_ID of the corresponding group do I need WHERE Group_ID = '$Key' ?
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Wed Jan 09, 2008 6:16 am Reply with quote

Shouldn't this line
SET GRAT_Grade = '$GRAT_Grade'

be
SET GRAT_Grade = '$value'

?
 
View user's profile Send private message
Donovan







PostPosted: Wed Jan 09, 2008 2:04 pm Reply with quote

Yeah... that was it.

I have other data that I am trying to process on the same form. Each record of IRAT_Grade[{$SOMS_KEY}] also has Group_ID and $UID.

Can I do the following?
Code:


//<!-- BEGIN Student Row -->"
   echo "<tr><td align=\"center\">$SOMS_KEY</td>"
  . "<td align=\"center\">$UID</td>"
  . "<td align=\"left\">$Name_First $Name_Last</td>"
  . "<td><input type='text' name='IRAT_Grade[{$SOMS_KEY}]' size='3' maxlength='3'></td>"   
  . "</tr>"; 
 echo "<input type='hidden' name='IRAT_Grade[{$Group_ID}]' value='$Group_ID'>\n";
 echo "<input type='hidden' name='IRAT_Grade[{$UID}]' value='$UID'>\n";
  }


Then on the page that processes this data do something like.

Code:
while (list($SOMS_KEY, $IRAT, $Group_ID, $UID) = each($IRAT_Grade)) {

$sql = "INSERT INTO ".$prefix."_tl_session_grades (Session_ID, UID, Group_ID, SOMS_KEY, IRAT_Grade, Academic_Year)". "VALUES ('$Session_ID', '$UID', '$Group_ID', '$SOMS_KEY', '$IRAT', '$Academic_Year')";
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
  }
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©