注意:使用未定义的常量

时间:2012-03-27 21:55:55

标签: php mysql

我收到此错误:

Notice: Use of undefined constant user_id - assumed 'user_id'
in C:\xampp\htdocs\euisample\language.php on line 44

我以为我用这个定义了它:

$id= " . $_SESSION[user_id] . ";

这是SQL语句;

$sql_insert = "INSERT into `language`
(`native`,`other`,`other_list`,`other_read`, `other_spokint`
,`other_spokprod`,`other_writ`  )
VALUES
('$native','$other','$other_list','$other_read','$other_spokint','$other_spokprod',
'$other_writ')  WHERE id= " . $_SESSION[user_id] . ")"

这是给我悲伤的最后一句话! 任何帮助都会很棒!

4 个答案:

答案 0 :(得分:1)

您在user_id之前忘记了最后一行查询中的$。

$sql_insert = "INSERT into `language`
(`native`,`other`,`other_list`,`other_read`, `other_spokint`
,`other_spokprod`,`other_writ`  )
VALUES
('$native','$other','$other_list','$other_read','$other_spokint','$other_spokprod',
'$other_writ')  WHERE id= " . $_SESSION[$user_id] . ")"

编辑: ' USER_ID'而不是$ user_id更有意义:)

答案 1 :(得分:1)

编辑错误提示:使用未定义的常量

if(isset($_SESSION['user_id']) && isset($native) && isset($other)&&............){
$sql_insert = "INSERT into `language`
(`native`,`other`,`other_list`,`other_read`, `other_spokint`
,`other_spokprod`,`other_writ`  )
VALUES
('$native','$other','$other_list','$other_read','$other_spokint','$other_spokprod',
'$other_writ')  WHERE id= " . $_SESSION['user_id'] . ")";
}

答案 2 :(得分:0)

应该是

$id= " . $_SESSION['user_id'] . ";

请注意元素' user_id'

周围的引号

你还应该在查询

中对var进行第二次调用

答案 3 :(得分:0)

您的语法问题是您需要引用user_id,如;

$_SESSION['user_id']

您将发现的下一个问题是SQL语句INSERT INTO xx WHERE yy不存在。您应该删除WHERE部分。

相关问题