简体   繁体   English

没有任何错误时不会执行我的查询

[英]My query isn't executed while there aren't any errors

I have a login script in which I also execute a query to log when and from where people try to log in to my site. 我有一个登录脚本,在其中我还执行查询以记录人们何时何地尝试从何处登录我的网站。 This little piece of code doesn't return any errors and the header works, but the query doesn't work for some reason. 这小段代码不返回任何错误,并且标头有效,但是由于某种原因该查询不起作用。 Does anyone have any idea what I'm doing wrong? 有人知道我在做什么错吗?

if($count==1){

$securityquery = "INSERT INTO security_kk (action,datetime,country,IP,Affected table,comment) VALUES (:action,:datetime,:country,:IP,:Affected_table,:comment)";
$q = $db->prepare($securityquery);
$q->execute(array(':action'=>"Login",
                  ':datetime'=>$datetime,
                  ':country'=>$country,
                  ':IP'=>$_SERVER['REMOTE_ADDR'],
                  ':Affected_table'=>"members",
                  ':comment'=>"Authenticated as ".$myusername));

$_SESSION['username'] = $myusername;
$_SESSION['privileges'] = $row['privileges'];
$_SESSION['email'] = $row['email'];
header("location:index.php");
}

I'm a beginner at PDO, but since there are no errors. 我是PDO的初学者,但是因为没有错误。 I don't know where to look. 我不知道在哪里看。

datetime is a data type in MySQL. datetime是MySQL中的一种数据类型。 Wrap that column identifier in ticks. 将列标识符括起来。 Also, column identifiers with spaces in their name must be wrapped in ticks. 另外,名称中带有空格的列标识符必须用打勾号包裹。

$securityquery = "INSERT INTO security_kk (`action`,`datetime`,`country`,`IP`,`Affected table`,`comment`) VALUES (:action,:datetime,:country,:IP,:Affected_table,:meta)";

Your error (or possibly one of the errors) is the difference between 您的错误(或可能是错误之一)是

:meta     // your query contains this

and

':comment'=>"Authenticated as ".$myusername;

Your array has no value for the placeholder named :meta 您的数组对于名为:meta的占位符没有任何价值

It doesn't hurt to check for errors using the error checking functions though, rather than having others try to figure out a simple typo. 不过,使用错误检查功能检查错误并没有什么坏处,而不是让其他人尝试找出简单的错字。

while there aren't any errors 没有任何错误

Because you aren't checking for them. 因为您不检查它们。

  1. DateTime is a datatype of mysql. DateTime是mysql的数据类型。
  2. check your Affected table column name - No space in column name 检查您受影响的表的列名-列名中没有空格

best way to use like below. 最佳使用方式如下。

$securityquery = "INSERT INTO security_kk (action,[datetime],country,IP,Affected table,comment) VALUES (:action,:datetime,:country,:IP,:Affected_table,:meta)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM