我正在使用 php mysql javascript 创建一个简单的 Web 开发测试,它们没有语法错误,但系统无法正常工作
谁能帮我 ????
索引.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>
客户端.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);
}
?>
连接管理器.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()
{
}
}
?>
连接.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");
?>
当我按下获取所有学生按钮时,控制台显示此文本
控制台日志
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}