I have spent an hour or so attempting to figure out this one error.. It looks right to me, but I am by far no expert. So I thought I would ask the experts! I keep getting this error:
Parse error: syntax error, unexpected ” (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in … on line 29
from this line of code:
eval("$var_value = $_REQUEST['{$value}']");
Here is the code around it..
function save_edits($var_name, $var_value)
{
eval("{$var_name} = sql_safe({$var_value});");
eval("mysql_query(\"UPDATE settings set {$var_name}='{$var_value}' where variable='{$var_name}'\") or die(mysql_error());");
}
foreach ($_REQUEST as $key => $value)
{
eval("$var_value = $_REQUEST['{$value}']");
save_edits($value, $var_value);
}
missing a
]is appears:Also missing a
):However, you should avoid
evalat much cost, especially with$_REQUESTs (implying user input). As it stands, this query would be harmful to your site:So how about a refactor:
However you should really look in to using:
Then you can sanitize both the name and the value field. You also probably want to look in to using PDO to prevent exploits better.