注意:未定义常量的使用


Notice: Use of undefined constant

我收到这个错误:

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] . ")"

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

您在查询的最后一行忘记了$,就在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更有意义:)

编辑错误通知:使用未定义的常量

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'] . ")";
}

应该是

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

注意元素"user_id"周围的引号

您还应该在查询

中对var的第二次调用周围加引号

语法的问题是您需要引用user_id作为;

$_SESSION['user_id']

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