Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am creating a simple web development test using php mysql javascript their is no syntax error but the system do not work as it should

can anyone help me ????

index.html

<html>
<head>

  <title>Testing Query</title>

 <script type="text/javascript" src="script/client.js"></script>

</head>
<body>
select the desired !
   <div>
      <p> <input type = "button" id = "requestedSTD" value = "Get All Student" onclick = "GetAllStudents();"/></p>
      <p> <input type = "button" id = "requestedSTD" value = "Get Student By ID" onclick = "GetStudentByID(2);"/></p>
   </div>
</body>
</html>

client.js

function GetAllStudents()
{
    var formRequest = new FormData();
    formRequest.append('getStudent', "getAllStudent");

    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", uploadComplete, false);
    xhr.open("GET", 'StudentService/getAllStudent.php');
    xhr.send(formRequest);

}

function GetStudentByID(id)
{

   var formRequest = new FormData();
   formRequest.append('sid', id);

   var xhr = new XMLHttpRequest();
   xhr.addEventListener("load", uploadComplete, false);
   xhr.open("POST", 'StudentService/getStudentByID.php');
   xhr.send(formRequest);   

}

function uploadComplete(evt)
{

  console.log(evt.target.responseText);
}

getAllStudent.php

<?php

require_once '../ConnectionManager.php';
 $response = array();
  $db = ConnectionManager::getInstance();

  $result = mysql_query("SELECT * FROM student") or die(mysql_error());

  if(mysql_num_rows($result) >0)
  {
      $response["student"] = array();

      while($roe = mysql_fetch_array($result))
     { 
      $student = array();
      $student["ID"] = $row["ID"];
      $student["Index"] = $row["Index"];
      $student["Name"] = $row["Name"];

      array_push($response["student"], $student);

     } 
    $response["success"] = 1;
    echo json_encode($response);
  }
  else
  {
      $response["success"] = 0;
      $response["message"] = "No  students found!!";

      echo json_encode($response);
  }


?>

getStudentByID.php

<?php
require_once '../ConnectionManager.php';

$response = array();
$db = connectionManager::getInstance();

if(isset($_POST["sid"]))
{
 $id = $_POST["sid"];
 $result = mysql_query("SELECT * FROM student WHERE ID = $id");

 if(!empty($result))
 {
    if(mysql_num_row($result) >0)
    {
      $row = mysql_fetch_array($result);

     $student = array();
     $student["ID"] = $row["ID"];
     $student["Index"] = $row["Index"];
     $student["Name"] = $row["Name"];

    $response ["success"] = 1;
    $response["$student"] = array();

    array_push($reponse["student"], $student);
    echo json_encode($response);
    }
    else
    {
     $response["success"] = 0;
     $response["message"] = "No Student found with this ID!!";
     echo json_encode($response);
    }
 }
 else
 {
    $response["success"] = 0;
    $response["message"] = "No Student found with this ID!!";
    echo json_encode($response);
 }

}
else
{
    $response["success"] = 0;
    $response["message"] = "Required feild(s) is missing!!";
    echo json_encode($response);
}

?>

ConnectionManager.php

<?php
require_once 'Connection.php';

class ConnectionManager
{
    static $connection = null;
    public static function  getInstance()
    {
        if(ConnectionManager::$connection == null);
           ConnectionManager::$connection = new Connection;
        return ConnectionManager::$connection; 
    }

    private function __construct()
    {   
    }
    private function __clone() 
    {
    }
}
?>

Connection.php

<?php

  class Connection
  {
     function __construct()
    {

      $this->connect();   
    }
    function __destruct()
    {

     $this->close();
    }
    function connect()
    {

       require_once __DIR__ . '/db_config.php';

       $connection = mysql_connect(SERVER, USER, PASSWORD) or die(mysql_error());
       $dbConnect = mysql_select_db(DATABASE) or die(mysl_error());
       return $connection;
    }

    function close()
    {
      mysql_close();
    }
  }
?>

db_config.php

<?php

 define('USER', "***");
 define('PASSWORD', "***");
 define('DATABASE', "studentservice");
 define('SERVER', "localhost");

?>

when i press the get all student button the console display this text

console log

GET http://localhost/studentservice/StudentService/getAllStudent.php

200 OK
        20ms    
client.js (line 9)

<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: array_push() expects parameter 1 to be array, null given in C:\wamp\www\studentservice\StudentService\getAllStudent.php on line <i>18</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0018</td><td bgcolor='#eeeeec' align='right'>677800</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0054</td><td bgcolor='#eeeeec' align='right'>708704</td><td bgcolor='#eeeeec'><a href='http://www.php.net/array_push' target='_new'>array_push</a>
(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>18</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: array_push() expects parameter 1 to be array, null given in C:\wamp\www\studentservice\StudentService\getAllStudent.php on line <i>18</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0018</td><td bgcolor='#eeeeec' align='right'>677800</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0057</td><td bgcolor='#eeeeec' align='right'>709072</td><td bgcolor='#eeeeec'><a href='http://www.php.net/array_push' target='_new'>array_push</a>
(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>18</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: array_push() expects parameter 1 to be array, null given in C:\wamp\www\studentservice\StudentService\getAllStudent.php on line <i>18</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0018</td><td bgcolor='#eeeeec' align='right'>677800</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0057</td><td bgcolor='#eeeeec' align='right'>709216</td><td bgcolor='#eeeeec'><a href='http://www.php.net/array_push' target='_new'>array_push</a>
(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>18</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: array_push() expects parameter 1 to be array, null given in C:\wamp\www\studentservice\StudentService\getAllStudent.php on line <i>18</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0018</td><td bgcolor='#eeeeec' align='right'>677800</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0059</td><td bgcolor='#eeeeec' align='right'>709360</td><td bgcolor='#eeeeec'><a href='http://www.php.net/array_push' target='_new'>array_push</a>
(  )</td><td title='C:\wamp\www\studentservice\StudentService\getAllStudent.php' bgcolor='#eeeeec'>..\getAllStudent.php<b>:</b>18</td></tr>
</table></font>
{"student":[],"Array":null,"success":1}
share|improve this question

closed as unclear what you're asking by Fluffeh, Quentin, Simon André Forsberg, icodebuster, tereško Oct 10 '13 at 22:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Please elaborate more on does not work as it should. What is your expectation and what is happening? Also, I feel there is way too much code in the question to go through. Narrowing it down to only the problematic part would be better. –  Harry Oct 10 '13 at 10:16
1  
Give us a lead ? What is not working ? Try to debug it step by step. Can you connect to your mysql server ? Can you fetch the data and return them ? –  Alexandre Nucera Oct 10 '13 at 10:17
    
this example must just display the data requested from the database as a json response –  LebDev Oct 10 '13 at 10:18
    
@ Harry the problem is that i do not know where is the error so i display all the code with the console .log hope that can anyone help me –  LebDev Oct 10 '13 at 10:27

1 Answer 1

up vote 1 down vote accepted

spelling mistake in getAllStudent.php line 18 array_push($reponse["student"], $student);

correct: array_push($response["student"], $student);

share|improve this answer
    
PS: for your easier to debug, you can find the XHR http URL via developer tools. Open the XHR URL in new tabs, you will see the error. –  Allen Chak Oct 10 '13 at 10:29
    
@ Allen Chak this was the error thank you for your help –  LebDev Oct 10 '13 at 10:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.