【发布时间】:2018-08-27 15:35:18
【问题描述】:
在我进行一些细微更改之前,PHP 页面运行良好。
错误原因是:$type = (int)$_POST['type'];
错误是:语法错误,意外 '' (T_ENCAPSED_AND_WHITESPACE),需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)
完整代码如下。
<?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;
}
?>
【问题讨论】:
-
你的代码在评论中??
-
你能告诉我们你的 HTML 代码吗?
-
你能发送你的实际代码吗!
-
我的错。我会发布完整的代码
-
您执行完全相同的查询两次。天才。