解析错误:解析错误,意外的T_封装了_和_空格,在第12行的C:\Programme\xamplite\xamplite\htdocs\insert.php中应为“]”

解析错误:解析错误,意外的T_封装了_和_空格,在第12行的C:\Programme\xamplite\xamplite\htdocs\insert.php中应为“]”,php,Php,我有一个错误: 解析错误:解析错误,意外的T_封装了_和_空格,在第12行的C:\Programme\xamplite\xamplite\htdocs\insert.php中应为“]” 在这一行: $sql="INSERT INTO tada (Nume, Prenume, Adresa, Tel, Anul, Nr.pantof) VALUES ('$_POST[Nume]','$_POST[Prenume]','$_POST[Adresa]','$_POST[Tel]','$_POST[An

我有一个错误:

解析错误:解析错误,意外的T_封装了_和_空格,在第12行的C:\Programme\xamplite\xamplite\htdocs\insert.php中应为“]”

在这一行:

$sql="INSERT INTO tada (Nume, Prenume, Adresa, Tel, Anul, Nr.pantof) VALUES ('$_POST[Nume]','$_POST[Prenume]','$_POST[Adresa]','$_POST[Tel]','$_POST[Anul]','$_POST[Nr.pantof]')";

如何修复它?

要在字符串中嵌入数组变量,应使用以下语法:

"... {$array['key']} ..."
而不是:

 "... $array['key'] ..."
除正常变量(如数组)外,其他变量均应使用花括号:

{$a['key']}
或对象:

{$a->var}
如果您的代码质量很差,您仍在使用旧的mysql扩展,请尝试以下方法:

$enc = "mysql_real_escape_string";
$sql = "INSERT INTO `tada` (`Nume`, `Prenume`, `Adresa`, `Tel`, `Anul`, `Nr.pantof`)
        VALUES ('".$enc($_POST['Nume'])."', '".$enc($_POST['Prenume'])."',
        '".$enc($_POST['Adresa'])."', '".$enc($_POST['tel'])."',
        '".$enc($_POST['Anul'])."', '".$enc($_POST['Nr.pantof'])."')";
还请注意,我在列名周围添加了倒勾。否则,MySQL可能会试图访问名为Nr的表来查找名为pantof的列,或者可能会由于自身的解析错误而死亡


在未来,学习基本原则!事实上有数百万,使用它们吧

这应该是公认的答案+1{$array[key]}也可以工作,但是出于可读性的原因,嵌入变量通常是个坏主意。