[英]Facing an error in a PHP page which was working fine before i made some minute changes
Facing an error in a PHP page which was working fine before i made some minute changes. 在我进行一些细微更改之前,PHP页面工作正常时遇到错误。
The error cause is : $type = (int)$_POST['type']; 错误原因是:$ type =(int)$ _ POST ['type'];
Error is : syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number(T_NUM_STRING) 错误是:语法错误,意外的''(T_ENCAPSED_AND_WHITESPACE),期望的标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)
FUll code is as follows. 完整代码如下。
<?php
require_once '../library/config.php';
require_once '../library/functions.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'search' :
search();
break;
default :
// if action is not defined or unknown
// move to main user page
header('Location: index.php');
}
/*
search() function used to search hadrware, software with user given criteria.
*/`
function search()
{
$type = $_POST['type'];
$name = $_POST['name'];
$hsql = "SELECT a.hostname, a.username, a.cpumodel, a.servicetag, a.monitormodel, a.phonext
FROM assets a WHERE a.username LIKE '%$name%' ";
$ssql = "SELECT a.hostname, a.username, a.cpumodel, a.servicetag, a.monitormodel, a.phonext
FROM assets a WHERE a.username LIKE '%$name%' ";
$data = array();
if($type == 1){
$result = dbQuery($hsql);
if(dbNumRows($result) == 0) {
header('Location: ../view.php?v=search&error=' . urlencode('No Hardware Found. Please try Again.'));
}else {
while($row = dbFetchAssoc($result)){
extract($row);
$data[] = array('hname' => $hname, 'uname' => $uname, 'cmodel' => $cmodel, 'stag' => $stag, 'mmodel' => $mmodel, 'pext' => $pext);
}
$_SESSION [result_data] = $data;
header('Location: ../search');
}//else
}
else {
$result = dbQuery($ssql);
if(dbNumRows($result) == 0) {
header('Location: ../view.php?v=search&error=' . urlencode('No Software Found. Please try Again.'));
}else {
while($row = dbFetchAssoc($result)){
extract($row);
$data[] = array('hname' => $hname,
'uname' => $uname,
'cmodel' => $cmodel,
'stag' => $stag,
'mmodel' => $mmodel
'pext' => $pext);
}
$_SESSION[result_data] = $data;
header('Location: ../search');
}
}endif;
}
?>
The problem is after your comment. 问题出在您发表评论后。 You open a backtick (most likely unintentionally) but dont close it.
您打开反引号(很可能是无意间),但不要关闭它。 Just remove it and it should work again.
只需将其删除,它应该可以再次工作。 You even can see it in the highlighting.
您甚至可以在突出显示中看到它。
/*
search() function used to search hadrware, software with user given criteria.
*/`
/* ^ there it is */
Also I´d like to point out, that your code is probably sql injection vulnerable. 我还要指出,您的代码可能容易受到sql注入的攻击。 This for example:
例如:
$type = $_POST['type'];
$name = $_POST['name'];
$hsql = "SELECT a.hostname, a.username, a.cpumodel, a.servicetag, a.monitormodel, a.phonext
FROM assets a WHERE a.username LIKE '%$name%' ";
$ssql = "SELECT a.hostname, a.username, a.cpumodel, a.servicetag, a.monitormodel, a.phonext
FROM assets a WHERE a.username LIKE '%$name%' ";
Your comment is not closed. 您的评论尚未关闭。
Put closing */
just before last curly bracket }
将结尾
*/
放在最后一个大括号之前}
Or 要么
If you do not want to have all the code commented then remove opening /*
just after the 如果你不想让所有的代码评论说,然后拆卸开口
/*
刚过
function search() {
The problem is with curly brackets in your variable name: 问题出在变量名中的花括号中:
$type = (int)${_POST['type']}
Correct way is without curly brackets: 正确的方法是没有大括号:
$type = (int)$_POST['type'];
Your comment above the function has a backtick character immediately after the closing comment marker. 您在函数上方的注释在结束注释标记后立即有一个反引号字符。 This is the cause of your issue.
这是导致您出现问题的原因。
If you remove this backtick, then you will resolve the problem. 如果删除此取消标记,则将解决问题。 It still won't work as there is one other compile error in the code you've given, which is due to a missing comma at the end of line 64. If you fix that as well then program will run, you'll find that there are additional logic errors as well as security issues (but I'll leave those for you to find for yourself).
由于您给出的代码中还有另一个编译错误,这仍然不起作用,这是由于第64行末尾缺少逗号引起的。如果您也对此进行了修复,则程序将运行,您会发现还有其他逻辑错误以及安全性问题(但我留给您自己寻找)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.