SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 54 of 54
  1. #51
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,128
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, that is partially my fault.

    PHP Code:
    //After teacher has entered marks...........
             
    $message =<<<EMAIL_MESSAGE
    'Dear Student, for your information, scores for your most recent examination have been uploaded. Please visit Med Buddy to view your score. Thank you.
    EMAIL_MESSAGE;
             if (
    $_SERVER["REQUEST_METHOD"] == "POST")
          {
             if (empty(
    $_POST['subject']))
             
    apologize("Please select a subject");
             
          
    // run update query setting the mark for the subject to $value 
             
    foreach ($_POST['mark'] as $studentid => $value)
             {
               
    $subjectExistsForStudent query("SELECT scores FROM marks WHERE studentid = ? AND subject = ?"$studentid$_POST['subject']);
               if (
    sizeof($subjectExistsForStudent) === 0
               {
                 
    $result query("INSERT INTO marks (studentid, subject, scores) VALUES (?, ?, ?)"$studentid$_POST['subject'], $value);
                 
                 if( 
    $result===false)
                 {
                   
    apologize("Could not update student scores");
                 }
                 else
                 {   
                     echo 
    "Inserted Data for $studentid<br />";
                     
    $studentEmailAddress query("SELECT email FROM users WHERE id = ?"$studentid);
                     
    $studentEmailAddress $studentEmailAddress['0']["email"];
                     
                     
    mail($studentEmailAddress'New Scores Uploaded!'$message);
                 }
               }
               else
               {
                 
    $result query("UPDATE marks SET scores = ? WHERE studentid = ? AND subject = ?"$value$studentid$_POST['subject']);
                 if( 
    $result===false)
                 {
                   
    apologize("Could not update student scores");
                 }
                  else
                 {   
                     echo 
    "Updated Data for $studentid<br />";
                     
    $studentEmailAddress query("SELECT email FROM users WHERE id = ?"$studentid);
                     
    $studentEmailAddress $studentEmailAddress['0']["email"];
                     
                     
    mail($studentEmailAddress'New Scores Uploaded!'$message);
                 }  
               }
             }
             die(
    "Quit Processing"); 
    Tell me what output you get for the above

  2. #52
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thisis what i got

    Inserted Data for 45
    Inserted Data for 46
    Inserted Data for 47
    Inserted Data for 48
    Inserted Data for 49
    Inserted Data for 50
    Quit Processing



    and the marks get inserted into the table too...

  3. #53
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,128
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, now do that again for the same subject, with new mark values and verify the data gets updated instead of inserted again.

  4. #54
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated Data for 45
    Updated Data for 46
    Updated Data for 47
    Updated Data for 48
    Updated Data for 49
    Updated Data for 50
    Quit Processing


    and the table too is well updated for the same subject... cpradio aka sherlock holmes lol... i m in awe of your debugging tricks...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •