我在我的网站空间上运行一个用于Android应用程序的脚本。虽然,它似乎没有用。在某些网站空间中,当我尝试访问它时,我得到一个空白站点,而在其他网站空间中,我收到500个内部服务器错误。虽然这个脚本应该正常工作,因为它曾经这样做。
它应该从表中获取所有信息并在一些INNER JOIN之后回显它。即使在一些mysqli_error检查和一些回声检查变量等之后,我也无法跟踪错误。
变量$ con确实存在,连接应该正常工作。我刚把它删除了堆栈溢出^^。
<?php
$subId = 1;
$sql = "SELECT articles.a_id, sciences.science, articles.title, articles.content, login.username, articles.date, articles.viewed, articles.timestamp FROM articles
INNER JOIN sciences ON articles.s_id = sciences.s_id
INNER JOIN login ON articles.author = login.id
WHERE articles.s_id = ".$subId."
ORDER BY timestamp DESC";
if (!$res = mysqli_query($con,$sql)) {
echo "FAIL";
echo mysqli_error($con);
}
else {
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array('a_id'=>$row[0],
'science'=>$row[1],
'title'=>$row[2],
'content'=>$row[3],
'author'=>$row[4],
'date'=>$row[5],
'viewed'=>$row[6],
'timestamp'=>$row[7]
));
}
echo json_encode(array("result"=>$result));
}
mysqli_close($con);
?>
编辑:我更新了我的代码:
<?php
$subId = 1;
$con = mysqli_connect("HOST", "USER", "PASSWORD", "DATABASE");
if (!$con)
{
echo "Cant't connect to MySQL.<br>";
echo "Debug: " . mysqli_connect_errno()
}
$sql = "SELECT articles.a_id, sciences.science, articles.title, articles.content, login.username, articles.date, articles.viewed, articles.timestamp FROM articles
INNER JOIN sciences ON articles.s_id = sciences.s_id
INNER JOIN login ON articles.author = login.id
WHERE articles.s_id = ".$subId."
ORDER BY timestamp DESC";
if (!$res = $con->query($sql))
{
echo "FAIL";
}
else
{
$result = array();
while($row = $con->fetchArray($res))
{
array_push($result); //use the query to rename fields, if needed
}
echo json_encode(array("result"=>$result));
}
?>
答案 0 :(得分:1)
我认为问题的一部分是你混淆了mysql和mysqli函数。你在程序上使用了mysqli,即:mysqli_fetch_array(),它并不存在。你必须转换为mysql,或者使用像这样的mysqli函数:
$subId = 1;
$con = mysqli_connect('host', 'user', 'pass', 'dbname');
if (!$con)
{
echo "Cant't connect to MySQL.<br>";
echo "Debug: " . mysqli_connect_errno()
}
$sql = "SELECT articles.a_id, sciences.science, articles.title, articles.content, login.username, articles.date, articles.viewed, articles.timestamp FROM articles
INNER JOIN sciences ON articles.s_id = sciences.s_id
INNER JOIN login ON articles.author = login.id
WHERE articles.s_id = ".$subId."
ORDER BY timestamp DESC";
if (!$res = $con->query($sql))
{
echo "FAIL";
}
else
{
$result = array();
while($row = $con->fetchArray($res))
{
array_push($result); //use the query to rename fields, if needed
}
echo json_encode(array("result"=>$result));
}
答案 1 :(得分:0)
将时间戳更改为 $logged = auth()->attempt(
['email' => $request['email'],
'password' => $request['password'],
'role' => 'user']);
if($logged) {
return $next($request); // probably it won't work. This is fine in middleware but not in controller
}
else{
return redirect()->back();
}
,因为它是保留字添加反引号
答案 2 :(得分:-1)
尝试在PHP中使用错误报告。通过在代码开头添加以下行来启用错误报告。
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
答案 3 :(得分:-2)
显然你忘记了
$con = mysqli_connect("localhost","my_user","my_password","my_db");
在脚本开头。