php - 通知 : Use of undefined constant

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

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

最佳答案

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

关于php - 通知 : Use of undefined constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9898304/

相关文章:

Mysql 原子 id 增量

javascript - 刷新 php 页面而不重新加载内容?

PHP在函数中声明全局变量

php - Laravel Eloquent 像对待 'archived_at' 一样对待列 'deleted_at'

mysql - 忽略关系表上其他用户的行

php - 使用$stmt->fetch(PDO::FETCH_ASSOC)时如何输出数据;

PHP:使用 mysql_fetch_array 更快地填充数组

从文件外部包含时,Javascript 代码不起作用

mysql - 用游标触发审计

mysql - 我想使用backgroundworker和datagridview显示mysql数据