<html>
    <title>
    </title>
    <body bgcolor="99ccff">
    <TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
    <TR>
    <TD WIDTH="900" HEIGHT="87" BACKGROUND="title.jpg" VALIGN="middle">
    <FONT SIZE="+1" COLOR="orange" align="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Online Examination Results System</b></FONT></TD>
    </TR>
    </TABLE>
    <TABLE BORDER="0" cellpadding="0" CELLSPACING="0" align="center">
    <TR>
    <TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow"><a href="ind.html" style="color: rgb(255,255,0)">Home</a></FONT></TD>
    <TD WIDTH="180" HEIGHT="40" BACKGROUND="but2.jpg" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow"><a href="dept.html" style="color: rgb(255,255,0)">Results</a></FONT></TD>
    <TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow"><a href="contactt.html" style="color: rgb(255,255,0)">Contact Us</a></FONT></TD>
    <TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow"><a href="feedback.html" style="color: rgb(255,255,0)">Feedback</a></FONT></TD>
    <TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow"><a href="gallery.html" style="color: rgb(255,255,0)">Gallery</a></FONT></TD>
    </TR>
    </TABLE>
    <TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
    <TR>
    <TD WIDTH="900" HEIGHT="50" bgcolor="brown" VALIGN="bottom">
    <FONT SIZE="+1" COLOR="yellow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marks Details</FONT></TD></tr></table>
    <table width="900" border="1" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td>
    <?php
    $host="localhost"; // Host name
    $username="root"; // Mysql username
    $password="root"; // Mysql password
    $db_name="project"; // Database name
    $tbl_name="add_marks"; // Table name
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $id= $_POST['id'];
    $Studentid= $_POST['Studentid'];
    $Semester= $_POST['Semester'];
    $sql="SELECT * FROM $tbl_name where Studentid='$Studentid' AND Semester='$Semester'";
    $result=mysql_query($sql);
    ?>
    <table width="900" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="900" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td colspan="4"><strong>List data from marks </strong> </td>
    </tr>
    <tr>
    <td align="center"><strong>id</strong></td>
    <td align="center"><strong>Studentid</strong></td>
    <td align="center"><strong>Department</strong></td>
    <td align="center"><strong>Subject</strong></td>
    <td align="center"><strong>Semester</strong></td>
    <td align="center"><strong>Marks</strong></td>
    <td align="center"><strong>Min</strong></td>
    <td align="center"><strong>Max</strong></td>
    <td align="center"><strong>Total</strong></td>
    <td align="center"><strong>Percentage</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><? echo $rows['id']; ?></td>
    <td><? echo $rows['Studentid'];?> </td>
    <td><? echo $rows['Department']; ?></td>
    <td><? echo $rows['Subject']; ?></td>
    <td><? echo $rows['Semester']; ?></td>
    <td><? echo $rows['Marks']; ?></td>
    <td><? echo $rows['Min']; ?></td>
    <td><? echo $rows['Max']; ?></td>
    <td><? echo $rows['Total']; ?></td>
    <td><? echo $rows['Percentage']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>

**pls help me to diplay the marks of selected students chosen from the form when we clck the submit button  **

Dani AI

Generated

The original page is missing a proper HTML form (as noted) so $POST values never arrive; that is the immediate blocker. Beyond that, the script uses the old mysql* API (removed in modern PHP), has no input validation or parameterization (SQL injection risk), and echoes DB values without HTML-escaping (XSS risk). A safe, minimal approach is: send a form with matching name attributes, require POST, use prepared statements (PDO or mysqli), and escape output with htmlspecialchars.

A concise example (replace credentials/table/column names to match the schema):

<form method="post" action="">
  <label>Student ID: <input type="text" name="Studentid"></label>
  <label>Semester: <input type="text" name="Semester"></label>
  <button type="submit">Show marks</button>
</form>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $sid = trim($_POST['Studentid'] ?? '');
  $sem = trim($_POST['Semester'] ?? '');

  if ($sid === '' || $sem === '') { echo '<p>Please select both fields.</p>'; exit; }

  try {
    $pdo = new PDO('mysql:host=localhost;dbname=project;charset=utf8mb4', 'dbuser', 'dbpass',
                   [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
    $stmt = $pdo->prepare('SELECT id, Studentid, Department, Subject, Semester, Marks FROM add_marks WHERE Studentid = :sid AND Semester = :sem');
    $stmt->execute([':sid' => $sid, ':sem' => $sem]);
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  } catch (Exception $e) {
    echo '<p>DB error.</p>'; // avoid showing raw errors in production
    exit;
  }

  if (empty($rows)) { echo '<p>No records found.</p>'; exit; }

  echo '<table>';
  foreach ($rows as $r) {
    echo '<tr><td>' . htmlspecialchars($r['Subject']) . '</td><td>' . htmlspecialchars($r['Marks']) . '</td></tr>';
  }
  echo '</table>';
}
?>

Troubleshooting tips and best practices: confirm form inputs use the exact name attributes expected by PHP; enable errors during development (errorreporting); test the SQL directly in a DB client; validate and cast inputs (e.g., numeric IDs) before querying; avoid hardcoding production DB passwords; and migrate away from mysql* to PDO/mysqli for compatibility and security.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.