Reputation: 3
Facing an error in a PHP page which was working fine before i made some minute changes.
The error cause is : $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)
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;
}
?>
Upvotes: 0
Views: 94
Reputation: 5032
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).
Upvotes: 0
Reputation: 2201
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. 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%' ";
Upvotes: 1
Reputation: 2591
The problem is with curly brackets in your variable name:
$type = (int)${_POST['type']}
Correct way is without curly brackets:
$type = (int)$_POST['type'];
Upvotes: 0
Reputation: 2591
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() {
Upvotes: 0