简体   繁体   English

mysql_query不满足所有指定参数

[英]mysql_query not fulfilling all specified parameters

so here is my code and I will tell you the problem after that: 所以这是我的代码,之后我将告诉您问题:

<script language='javascript' type='text/javascript'>
    setInterval( function() {
    $('#responsechat<?php echo $otherchatuser ?>').load('echogetconversation.php?username=<?php echo $username; ?>&otherchatuser=<?php echo $otherchatuser; ?>&numberofmessages=<?php echo $numberofmessages; ?>');
    <?php
    $subtractlogintime8 = time() - 600;
    $data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and time > '$subtractlogintime'");
    $numrows8 = mysql_num_rows($data8);
    ?>
    if (<?php echo $numrows8; ?> == 1 )
    {
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").innerHTML = '<img src="loggedin.png">';
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").style.marginLeft = '5px';
    }
    else
    {
    document.getElementById("checkloggedin<?php echo $otherchatuser; ?>").innerHTML = '';
    }
    }, 4000);
    </script>

This is my code, which gets users who are logged in and also does other things. 这是我的代码,它使登录的用户也可以执行其他操作。 The problem that I am having occurs on this line: 我遇到的问题在此行上发生:

 $data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and time > '$subtractlogintime'");

The query successfully gets users from the database, but seems to be ignoring the "and time > '$subtractlogintime'");" part of the query. I have no idea why this is occurring and anyone who could possibly tell me what I have forgotten would be extremely appreciated. Thanks. 该查询成功地从数据库中获取了用户,但似乎忽略了查询的“和时间>'$ subtractlogintime'“);”部分。我不知道为什么会这样,任何人都可以告诉我我拥有遗忘将不胜感激。

TIME is a reserved keyword in MySQL because of the TIME datatype. 由于TIME数据类型,TIME是MySQL中的保留关键字。 If it's not crashing, you would probably better off backticking your "TIME" keyword to refer to the field time . 如果它没有崩溃,则可能最好反引号“ TIME”关键字来引用字段time

$data8 = mysql_query("SELECT * FROM loggedin WHERE username='$otherchatuser' and `time` > '$subtractlogintime'");

Also note that, this code COULD be prone to SQL injection but we can't be sure without seeing the full code... 另请注意,此代码可能易于进行SQL注入,但我们无法确定是否没有完整的代码...

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

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