简体   繁体   English

在进行一些细微更改之前,PHP页面工作正常,但遇到错误

[英]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.

相关问题 我测试用的简单表格的PHP / MySQL错误(我正在尝试向自己介绍一些MySQL / PHP) - PHP/MySQL error for a simple form i made for testing (i'm trying to teach myself some MySQL/PHP) 我创建了此代码,如果保留在标题中,则可以正常工作,但不能在php wordpress函数中工作 - i created this code which is working fine if kept in header but not working in functions php wordpress 我有一个可以正常运行的php错误日志,但我也想显示错误“产生”的时间 - I have a php error log which works correctly, but I'd also like it to show the time the error was “made” 我创建的php页面应该在mysql表中添加条目,但是没有对表做任何事情 - The php page that I made which is supposed to add entries to a mysql table is not doing anything to the table 我的 php 表单停止工作。 之前还好好的 - My php form stopped working. It was working fine before, 是否有可能在php中保存在网页上所做的更改而无需发送到数据库中 - is it possible in php to save changes made on web page without sending into database PHP,使页面自动检测管理员所做的更改 - PHP, make the page automatically detect changes made by the admin PHP 文件上传不再有效,未进行任何更改(Plesk 托管) - PHP File Upload No Longer Working, No Changes Made (Plesk Hosting) 托管中的 PHP 输出错误,但在 xampp 上工作正常 - PHP Output error in hosting but working fine on xampp 如何让 php 知道我在输入中进行了更改? - How do I let php know that I made changes In input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM