Jump to content

using php to retrieve data after updating mysql


Recommended Posts

I have a web site that lists students in a database on a server, and can add a students details. It then relists the students pulling the new list off the database.  All worked well until I transferred everything to a new webhost.   It still works to the point of relisting when I get the old list not the updated one. Checking the database(mysql) directly it has actually put the new student in. and if I log out of the web site and back in the new student's details are there.  how do get this to work? relevent code is below:


function listStudents(password){

var oReq = new XMLHttpRequest();
    oReq.onload = function() {
        // This is where you handle what to do with the response.
        // The actual data is found on this.responseText
    allTheStudents =  JSON.parse(this.responseText);
     select = document.getElementById("audioFile");
for(index in allTheStudents) {
    select.options[select.options.length] = new Option(allTheStudents[index], index);

    alert("There are no students");

document.getElementById("fileLabel").innerHTML= "Select Student(s) from the list:";
document.getElementById("fileLabel").style = "display:show;font-family: Calibri; font-size: 16px; font-weight: bold;color:#E3C208;";
    oReq.open("get", "listStudents.php?x=" + username, true);

function addStudent(){

familyName = document.getElementById("familyNameId").value;
givenName = document.getElementById("givenNameId").value;
email = document.getElementById("emailId").value;
studentdetails = familyName+","+ givenName +","+email+","+ username ;
listNewStudent = familyName+" "+ givenName +" "+email;
addaStudent = JSON.stringify(studentdetails);
var oReq = new XMLHttpRequest();
    oReq.onload = function() {
    oReq.open("get", "saddStudent.php?x=" + addaStudent, true);
    //alert("username "+ username);
    alert("about to list");

    select = document.getElementById("audioFile");
    //select.options = new Option(listNewStudent);
    select.options[select.options.length] = new Option(listNewStudent);



$studentdetails = json_decode($_GET["x"],false);

//$var = file_get_contents('php://input');
//$studentArray = json_decode($var);

//$length = count($studentArray);
$servername = xxxxx
$user =  xxxxxx
$db ='xxxxxx

    // Create connection
    $con = new mysqli($servername, $user, $pass, $db) or die("Unable to connect to Database: " . $db);

    if ($con->connect_error) {
      die("Connection failed: " . $con->connect_error);

    $studentElements = str_getcsv($studentdetails,",","");
    $sqla = "INSERT INTO students (familyName,givenName,email,)
    VALUES ('$fname','$gname','$ename);";

if (mysqli_multi_query($con,$sqla) === TRUE) {
  //      echo "New records created successfully";
  } else {



Thanks in advance

Edited by jdauthre
minor correction
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...