'I want to retrive data in tabular form using ajax and php

I have written the following code

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-    scale=1.0">
        <title>contact.dat</title>
      <body>
      <div id="demo">
    <h2>Retrive data by ajax</h2>
    <button type="button" onclick="printdata()">Retrive data</button>
    </div>
    
    <script>
    function printdata() {
      const xhttp = new XMLHttpRequest();
      xhttp.onload = function() {
        document.getElementById("demo").innerHTML +=this.responseText;
      }
      xhttp.open("GET", "contact.dat");
      xhttp.send();
    }
    </script>
      </body>
    
    <?php
    
    $fp = fopen('contact.dat', 'r');
    echo "<table border=1>";
    echo "<tr><th>Sr. No.</th><th>Name</th><th>Residence No.</th><th>Mob.
    no.</th><th>Address</th></tr>";
    while ($row = fscanf($fp, "%s %s %s %s %s")) {
        echo "<tr>";
        foreach ($row as $r) {
            echo "<td>$r</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
    fclose($fp);
    ?>
    
    </html>

its showing me this output I want to show data when I click on the button. I'm new in both JavaScript as well as PHP. is there any way to perform something like

if(isset(printdata();))

then run php code block???



Solution 1:[1]

Here lies the wrong

/usr/bin/env /opt/jdk17/bin/java .... java.ASG6Ba 

Probably the file that you try to execute is ASG6Ba.java.

The provided file java.ASG6Ba with the ending ASG6Ba makes no sense for java to be executed.

Also java is a prohibited name for packages in java and since the file provided is java.ASG6Ba, java thinks that java is a package name and then follows the class name ASG6Ba. This is the specific reason the error is thrown.

Prohibited package name: java

This is also described in java documentation in chapter 6.1

The first component of a package or module name must not be the identifier java. Package and module names that start with the identifier java are reserved for packages and modules of the Java SE Platform

Solution 2:[2]

You doun't expose the database structure (as required in Stackoverflw for SQL questions), so my answer is shown on some generic table and field names. Also, I'm not sure I clearly understand your question.

To find all students that have roll_number from a particular course (assumes tables Courses, Students and StudentErols):

SELECT ST.LastName, ST.FirstName
FROM Couses as CRS
LEFT JOIN StudentEntrols as SE on SE.CourseID = CRS.ID
LEFT JOIN Students as ST ON ST.ID = SE.StudentID 
WHERE CRS.ID = " & Me.CourseID & ";

To check if particular student has roll_number in a particular course, see if you get any results from this modified query:

SELECT ST.LastName, ST.FirstName
FROM Couses as CRS
LEFT JOIN StudentEntrols as SE on SE.CourseID = CRS.ID
LEFT JOIN Students as ST ON ST.ID = SE.StudentID 
WHERE CRS.ID = " & Me.CourseID & "
  AND ST.ID = " & Me.StudentID & "

To create attendance of all students who are enrolled in a particular course (assumes tables Courses, Students and Attendance):

INSERT INTO Attendance as ATT (StudentID, CourseID)
SELECT ST.ID, CRS.ID
FROM Courses as CRS
LEFT JOIN StudentEntrols as SE on SE.CourseID = CRS.ID
LEFT JOIN Students as ST ON ST.ID = SE.StudentID 
WHERE CRS.ID = " & Me.CourseID & ";

You can modify that to your database structure and add parameters (which are probably overkill, considering it's just Access, run probably by a single staff).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Oak_3260548