我创建了一个自定义函数,但出现此错误。我认为脚本中没有“解析错误”。

Parse error: syntax error, unexpected ',', expecting '&' or T_VARIABLE in C:\wamp\www\web template\test.php on line 8




<?php
require('global script/php/dbConnect.php');

$varName = 'sd';

echo checkDBDuplicate('account_list', 'memberID', $varName);

function checkDBDuplicate(tableName, dbFieldName, variableName)
{
    $tableName = tableName;
    $dbFieldName = dbFieldName;
    $variableName = variableName;

    $searchDuplicate = mysql_query('
        SELECT $dbFieldName
        FROM $tableName
        WHERE $dbFieldName = $variableName
        ') or die(mysql_error());
    $countRow = mysql_num_rows($searchDuplicate);

    return $countRow;
}
?>


该脚本的目的是测试我是否可以在SELECT语句中使用变量。

最佳答案

变量应具有$前缀。所以

function checkDBDuplicate(tableName, dbFieldName, variableName) {


是错的

function checkDBDuplicate($tableName, $dbFieldName, $variableName) {


显然,更是如此,因此:

$tableName = tableName;
$dbFieldName = dbFieldName;
$variableName = variableName;


需要同样的待遇

07-24 21:56