嘿,我目前正试图在表中插入一个全局变量。我传递的其他值也是变量,但它们被正确发送。
这是我的问题。我的错误处理没有捕获任何内容。
$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,其中包含变量和数据库登录信息。它正在被包括在顶部。(不知道这是否相关)
发布于 2012-10-04 06:00:58
因为您没有插入IP STATUS,所以.Which不是空的。

\
您应该将其设置为null或为其输入一些值。
如果在函数中使用查询,请使用以下方式
function (){
//than define
$globat $masterUserId;
// use the global defination
// than use this variable with global value
}发布于 2012-10-04 06:02:31
不要使用mysql_*。用mysqli_*或PDO::替换它们。
你试过echo mysql_query()吗?这样做。将mysql_query("...");替换为die("...");,并将其放在phpMyAdmin中,然后尝试执行。
在你的桌子上,我看到IP Status是一个NOT NULL。所以这可能会引发异常。在表中使用default值。
是的,你在mysql_error()里得到的结果是什么?
发布于 2012-10-04 10:01:25
为什么在查询中使用‘或’‘?我用PHP函数斯普林特清理了查询,并为EntryID使用了NULL (自动增量)
$query = sprintf("INSERT INTO IPmanagement (EntryID,userId, NameUsed, EmailUsed, IPStatus, Ip) VALUES (NULL,%s,%s,%s,'0',%s)",
$masterUserId , $Entry['LeadName'] , $Entry['LeadEmail'] , $ip ));
$result = mysql_query($query);您还应该使用MySQLi或PDO。
https://stackoverflow.com/questions/12721068
复制相似问题