【发布时间】:2012-02-11 17:24:55
【问题描述】:
我该怎么做?
根据 PHP.net,
$a = "hi";
$hi = 2;
$$a; // returns 2
但是,我需要:
$i = 2;
$_POST['link$i']; // I need this to return the same thing as $_POST['link2']
这是我的代码。
for ($i = 1; $i <= 40; $i++)
{
if(!empty($link$i))
{
$link$i = mysql_real_escape_string($_POST['link$i']);
mysql_query("
INSERT INTO links (link, rimageid) VALUES
('".$link$i."', '".$id."') ");
} else { }
}
我这样做的原因是因为我有很多文本输入字段将它们的值发布到这个文件中,我想通过 for 循环定义和插入它们的每个值,而不是手动插入每个链接到mysql。
现在,我明白了:
Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in C:\xampp\htdocs\new2.php on line 22
我该怎么做呢? 谢谢!
【问题讨论】:
-
变量插值适用于double quoted strings,而不是单引号。所以
$_POST["link$i"]将是内置的语言。
标签: php variables if-statement for-loop