PHP语法错误,我找不到

时间:2013-07-02 23:27:22

标签: php error-handling syntax-error

我有一个包含以下php代码的文件:

<?php
session_start();
include_once("config.php");
include_once("functions.php");
include_once("class/db.class.php");
$config = new config($db_host, $db_user, $db_pass, $db_name);
$db = new db($config);
$db->openConnection();

switch ($_POST['mode']) {
    case 'update':
        if(mysql_query("UPDATE table_name SET id_negozio = '".$_POST['negid']."', nome='".mysql_real_escape_string(strtolower($_POST['nome']))."', cognome='".mysql_real_escape_string(strtolower($_POST['cognome']))."', indirizzo='".mysql_real_escape_string($_POST['indirizzo'])."', CAP='".$_POST['cap']."', city='".mysql_real_escape_string($_POST['city'])."', tel='".$_POST['tel']."', email='".strtolower($_POST['email'])."', provincia='".strtoupper($_POST['provincia'])."', data_nascita = '".$_POST['datanascita']."', luogo_nascita='".mysql_real_escape_string($_POST['luogonascita'])."', doc_number='".strtoupper($_POST['docnum'])."', doc_type='".$_POST['doctype']."', doc_data='".$_POST['docdata']."', cf='".strtoupper($_POST['cf'])."', doc_exp='".$_POST['doc_exp']."', doc_rilascio='".$_POST['doc_rilascio']."' WHERE id = ".$_POST['id']." ")){
            echo "ok";
        }
    break;

    case 'salvataggio_finale':
        if(mysql_query("UPDATE table_name SET salvato = 1 WHERE id = ".$_POST['id']." ")){
            logit("Creato nuovo cliente.", $_POST['idneg']);
            echo "ok";
        }
    break;

    case 'del':
        if(mysql_query("DELETE FROM table_name WHERE id = ".$_POST['id']." ")){
            logit("Eliminato cliente con id ".$_POST['id']."", $_POST['idneg']);
            echo "deleted";
        }
    break;
}
unset($db);
?>

在我的服务器上,我有error_log,显示38个输入错误的条目:

[..] PHP Parse error:  syntax error, unexpected '{' in /home/.../filename.php on line 12

第12行是案例'更新'之后的 if语句 我不明白为什么我不应该把括号或真正的错误。

1 个答案:

答案 0 :(得分:1)

您是否检查class/db.class.php是否有未公开的引号(“)?

在将POST变量连接到查询时也要注意可能的sql注入。