-1

ここで私のコードの問題を理解できません。テーブルから情報を取得しようとしています。次に、「2:00」のように見える Current_Time から 1 秒を引きます。問題は、私が得ることです:

「SQL 構文にエラーがあります。使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。1 行目付近で 'Current_Time) VALUES('22')' を使用してください」

どこから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>
4

2 に答える 2

1

Current_TimeはMySQLのキーワードです。その周りに`を付けてみてください(これは一重引用符ではなく、バックティック[thx maiorano84]-Tabキーの上です)

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

$query = "INSERT INTO Live_Auctions(`Current_Time`) VALUES('".$newTime."')";

編集:

SELECTステートメントを次のように変更します。

$query = "SELECT DATE_ADD(`Current_Time`, INTERVAL '-1' MINUTE) FROM Live_Auctions WHERE ID='1'";
于 2012-10-04T03:20:27.397 に答える
0
//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."')";
于 2012-10-04T03:45:31.640 に答える