PHP Web Host - Quality Web Hosting For All PHP Applications $35/month $250/year (Unlimited) - $25/month - 200,000 impressions - Your Ad Could be Here - Click For Details
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Donovan
Client


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

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

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: 15062
Location: Kansas

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

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

be
SET GRAT_Grade = '$value'

?
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Donovan
Client


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

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

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>");}
  }
View user's profile Send private message Visit poster's website ICQ Number
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum