Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MySQL语法错误“您的SQL语法有错误”_Php_Mysql_Sql_Mysql Error 1064 - Fatal编程技术网

PHP MySQL语法错误“您的SQL语法有错误”

PHP MySQL语法错误“您的SQL语法有错误”,php,mysql,sql,mysql-error-1064,Php,Mysql,Sql,Mysql Error 1064,我无法在这里找到我的代码的问题。我试图从表中获取信息,然后从当前时间中减去1秒,看起来像“2:00”。问题是,我得到: 您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第1行的“Current_Time VALUES”22附近使用的正确语法 我甚至不知道它是从哪里来的 谢谢,我真的很感激 <?php $connection = mysql_connect('localhost', 'aleckaza_admin', 'pswd'); if (!$connection

我无法在这里找到我的代码的问题。我试图从表中获取信息,然后从当前时间中减去1秒,看起来像“2:00”。问题是,我得到:

您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第1行的“Current_Time VALUES”22附近使用的正确语法

我甚至不知道它是从哪里来的

谢谢,我真的很感激

<?php

$connection = mysql_connect('localhost', 'aleckaza_admin', 'pswd');
if (!$connection) {
    die('Could not connect: ' . mysql_error());
}

if (isset($_GET['id']) && isset($_GET['time'])) {
    mysql_select_db("aleckaza_pennyauction", $connection);
    $query = "SELECT Current_Time FROM Live_Auctions WHERE ID='1'";
    $results = mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_array($results)) {
        $newTime = $row['Current_Time'] - 1;
        $query = "INSERT INTO Live_Auctions(Current_Time) VALUES('".$newTime."')";
        $results = mysql_query($query) or die(mysql_error());
    }
}

if (isset($_GET['getTime'])) {
    mysql_select_db("aleckaza_pennyauction", $connection);
    $query = "SELECT `Current_Time` FROM Live_Auctions WHERE ID='".$_GET['getTime']."'";
    $results = mysql_query($query) or die(mysql_error());
}

function beginGetAllInfo() {
    GLOBAL $connection;
    mysql_select_db("aleckaza_pennyauction", $connection);
    $query = "SELECT * FROM Live_Auctions";
    $results = mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_array($results)) {
        if (!isset($_GET['getTime'])) {
        echo "
        <table width=200px height=360px cellspacing=0 cellpadding=1 style='border-color: #000; border-style: solid; border-width: 1px;'>
            <tr>
                <td colspan=2 style='font-size: 14px; color: #2700EB; font-family: Arial,Helvetica,sans-serif;'><center><strong>".$row['Product_Name']."</font></strong></center></td>
            </tr>
            <tr>
                <td colspan=2><center><img width=70% src='".$row['Image_URL']."'></center></td>
            </tr>
            <tr>
                <td id='txtHint' colspan=2 bgcolor=#000 height=90px><center><font color=#fff size=5px>$".$row['Current_Price']."</font><br /><font color=#fff size=3px>Timer set @ ".$row['Current_Timer']."sec</font><br /><font color=#fff size=5px>".$row['Current_Time']."</font><br /></center></td>
            </tr>
        </table>";
        } else {

        }
    }
}

?>

<html>
    <head>
        <title>Auction</title>
        <script type="text/javascript">
function getTime()
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","auction.php?getTime=1",true);
xmlhttp.send();
}

while (1) {
    getTime();
}
</script>
    </head>
    <body>
        <?php beginGetAllInfo(); ?>
    </body>
</html>

Current_Time是MySQL中的一个关键字,试着在它周围加上`顺便说一句,这不是一个单引号,它是一个倒勾[thx maiorano84]——在TAB键上方

$query = "SELECT `Current_Time` FROM Live_Auctions WHERE ID='1'";

编辑:

我会将您的SELECT语句更改为:

$query = "SELECT DATE_ADD(`Current_Time`, INTERVAL '-1' MINUTE) FROM Live_Auctions WHERE ID='1'";

$newTime=$row['Current_Time']-1;返回22而不是timeBackticks是您正在寻找的术语。很高兴知道,我不知道=。正在更新帖子。您是否将其放入insert和select语句中?看起来您使用了两次当前时间。是的,我使用了,但没有任何不同。数据库中当前时间的数据类型是什么?你的成绩是22分。这是该字段的有效值吗?它在INSERT上爆炸了,但是在语法上它看起来还可以…不,它只是给了我一个粗体的PHP错误。
$query = "SELECT DATE_ADD(`Current_Time`, INTERVAL '-1' MINUTE) FROM Live_Auctions WHERE ID='1'";
//Current_Time is a reserve function in sql

//change this line from this :
$query = "INSERT INTO Live_Auctions(Current_Time) VALUES('".$newTime."')";

//to this :
//surround the Current_Time with backtick (not single quote)
$query = "INSERT INTO Live_Auctions(`Current_Time`) VALUES('".$newTime."')";