解析错误:语法错误,第9行的C:\ wamp \ www \ insert_data.php中的意外'='

时间:2013-05-24 04:14:50

标签: php

所以我收到了这个错误:

Parse error: syntax error, unexpected '=' in C:\wamp\www\insert_data.php on line 9

在这一行:

$std-id = $_POST['std_id'];

我的PHP代码是:

<?php

if ( isset($_POST['submitted'] ) )
{
include ('mysql_connect.php') ;

$std-id = $_POST['std_id'];
$std-name = $_POST['std_name'];
$std-year = $_POST['year'];
$std-degree = $_POST['degree'];

$sqlinsert = "INSERT INTO student ( ID , Name , Year ,  Degree ) VALUES (' $std-id ' ,   ' $std-name ' , ' $std-year ' , ' $std-degree ' ) ";

if (!mysql_query ( $dbcon, $sqlinsert ) ) {
die( ' error inserting new record ' ) ;
} // end of nested if statment

$newrecord = " 1 record added to the database " ;
} // end of the main if statement

?>

1 个答案:

答案 0 :(得分:7)

您的变量名称中不能包含破折号。 From the manual

  

有效的变量名称以字母或下划线开头,后跟任意数量的字母,数字或下划线。