Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:02:55+00:00 2026-05-30T04:02:55+00:00

i have a table and it display all the record in the table using

  • 0

i have a table and it display all the record in the table using $row. It generates multiple lines because it displayed all the value from the table. Then inside the table i created a form that comprised of only one single row. I want to record one value of that single $row using the studentnumber and subjectcode which is both from the $row in my query. Sorry for my confusing question and THANKS in advance.

code:

  echo "<form name=\"grades\"  action=\"insert.php\" method=\"post\" onsubmit=\"javascript:return confirm('Confirm Grade Submission?');\">";

  echo "<td class=\"studentlist\">" . $row['studentnumber'] . "</td>";
  echo "<td class=\"studentlist\">" . $row['subject'] . "</td>";
  echo "<td class=\"studentlist\"><input type=\"text\" id= \"q1\" name=\"q1\" class=\"tbox\"></td>";
  echo "<td class=\"studentlist\"><input type=\"text\" id= \"q2\" name=\"q2\" class=\"tbox\"></td>";
  echo "<td class=\"studentlist\"><input type=\"text\" id= \"q3\" name=\"q3\" class=\"tbox\"></td>";

  echo "<td class=\"studentlist\"><input type=\"submit\" value=\"Submit\"></td>";
  echo "</form>";

insert.php

$studentnumber= $_POST['studentnumber'];
$subjectcode= $_POST['subjectcode'];

 $query = ("SELECT * FROM grades WHERE studentnumber = '$studentnumber' && subjectcode = '$subjectcode'");
 $result=mysql_query($query);

if($result)
  {
    if(mysql_num_rows($result) == 1)

      {
      $sql="INSERT INTO grades ( q1, q2, q3 )
        VALUES('$_POST[q1]','$_POST[q2]','$_POST[q3]'')";

            if (!mysql_query($sql,$con))
              {
                die('Error: ' . mysql_error());
              }
              echo "<script type='text/javascript'>alert('Grade Successfully Submitted');location.href = '../administrator/admin_home.php';</script>";
      }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:02:57+00:00Added an answer on May 30, 2026 at 4:02 am

    First things first, you will need to pass the studentnumber and subjectcode from the form to the second page which processes the MySQL. For this you can use some hidden form fields, i.e. use in place of the lines where you echo studetnumber and subject.

    echo "<td class=\"studentlist\"><input type=\"hidden\" name=\"studentnumber\" value=\" . $row['studentnumber'] . \">" . $row['studentnumber'] . "</td>";
    echo "<td class=\"studentlist\"><input type=\"hidden\" name=\"subject\" value=\" . $row['subject'] . \">" . $row['subject'] . "</td>";
    

    It’s hard to be specific without seeing the full table design of grades, however the following would insert the data you are trying to insert however it would error if studentnumber and subjectcode formed a UNIQUE key, and the row already existed

    $sql = "INSERT INTO grades (
        studentnumber,
        subjectcode,
        q1,
        q2,
        q3
    ) VALUES (
        '".$_POST['studentnumber']."',
        '".$_POST['subject']."',
        '".$_POST['q1']."',
        '".$_POST['q2']."',
        '".$_POST['q3']."'
    )";
    

    In order, if it hits a duplicate studentnumber/studentcode combination, to make it update then you just add “ON DUPLICATE KEY” syntax to the end, i.e.

    $sql = "INSERT INTO grades (
        studentnumber,
        subjectcode,
        q1,
        q2,
        q3
    ) VALUES (
        '".$_POST['studentnumber']."',
        '".$_POST['subject']."',
        '".$_POST['q1']."',
        '".$_POST['q2']."',
        '".$_POST['q3']."'
    )
    ON DUPLICATE KEY UPDATE
        q1 = VALUES(q1),
        q2 = VALUES(q2),
        q3 = VALUES(q3)";
    

    This will then update q1,q2,q3 with whatever values were specified for the row(s) that had duplicate student number/subject combinations.

    Finally if you just want to ignore duplicates, then the following will suffice (note addition of IGNORE).

    $sql = "INSERT IGNORE INTO grades (
        studentnumber,
        subjectcode,
        q1,
        q2,
        q3
    ) VALUES (
        '".$_POST['studentnumber']."',
        '".$_POST['subject']."',
        '".$_POST['q1']."',
        '".$_POST['q2']."',
        '".$_POST['q3']."'
    )";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many applications have grids that display data from a database table one page at
I have a table maintaining record of all reservations made. Now the start date
I have written my jsp using <display:table> to display search results. The <display:table> requires
I have web page in PHP which displays all records in a table. I
I have a table of suppliers, and tables Computers, Cameras, Displays all containing the
I have code: <display:table name=sessionScope.allUserslist id=userList export=false pagesize=1> <display:column title=Select style=width: 90px;> <input type=checkbox
I have a Database table that I want to display in a DataGridView. However,
I have an SQL table like this : sales(product,timestamp) I want to display a
I have a long list of data that I want to display in table
So I have a parent that defines a onmouseup event that hide/display a table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.