嘿,我目前正在尝试将一个全局变量插入到一个表中。我传递的其他值也是变量,但它们被正确发送。
这是我的查询。我的错误处理没有捕获任何内容
$result = mysql_query("INSERT INTO IPmanagement (userId, NameUsed, EmailUsed, IPStatus, Ip) VALUES ('" .$masterUserId . "', '" . $Entry['LeadName'] . "', '" . $Entry['LeadEmail'] . "', '0', '" . $ip . "')") or die(ErrorException("Function 6", "Error when processing the current lead. your data is unaffected and if the proccess continues please contact an Admin.", mysql_error(),$_SERVER['REMOTE_ADDR'], CurrentPath(), $masterUserId));
我在函数之前定义的全局变量是
$masterUserId = "1";
我尝试在它发送之前回显该变量,它正确地回显出来,但我的表的值为 0。
这是我如何设置表格的屏幕截图。
知道发生了什么。我很困惑,并尝试以不同的方式编写相同的代码,但它仍然给了我同样的问题。此外 $masterUserId 将始终是一个 int 值
编辑:还想提一下变量是不同的 .php,它包含变量和数据库登录信息。它被包含在顶部。 (不知道这是否相关)
最佳答案
因为您没有插入 IP STATUS
。它不为空
\
您应该将其设置为 null
或为其输入一些值。
如果你在函数中使用查询而不是像这样使用
function (){
//than define
$globat $masterUserId;
// use the global defination
// than use this variable with global value
}
关于php - 将变量值插入 MySQL 表时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12721068/