parse error in eval() - eval()'d code [closed]
Where is the problem in my eval code??? because Apache said:
Parse error: syntax error, unexpected T_STRING in E:\xa开发者_如何学JAVAmpp\htdocs\1php\mas_res\inc\mysql_class.php(120) : eval()'d code on line 1
my code:
$type1 = "row";
$query1 = mysql_query("SELECT * FROM table");
$textToEval = "mysql_fetch_{$type1}($query1);";
$query = eval($textToEval);
And what is the correct mode??
Thanks ..
Don't use eval! Use PHP's variable functions:
$function = 'mysql_fetch_' . $type1;
$query = $function($query1);
Oh, and if you want to know, what was the fault: You forgot to escape the $
in $query1
. It should be \$query1
.
精彩评论