Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I cannot figure out the issue with my code here. I am trying to take info from the table, then subtract 1 second from Current_Time which looks like '2:00'. The problem is, I get:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Current_Time) VALUES('22')' at line 1"

I don't even understand where it gets 22 from.

Thanks, I really appreciate it.

<?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>
share|improve this question

closed as too localized by Jocelyn, hjpotter92, Alvin Wong, Vishal, andrewsi May 7 '13 at 3:24

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
$newTime = $row['Current_Time'] - 1; is returning 22 instead of time – gtgaxiola Oct 4 '12 at 3:20
    
How do I fix the issue? – Alec Oct 4 '12 at 3:22

2 Answers 2

Current_Time is a keyword in MySQL, try putting ` around it (that's not a single quote btw, it's a backtick [thx maiorano84] - above the TAB key)

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

and

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

EDIT:

I would change your SELECT statement to:

$query = "SELECT DATE_ADD(`Current_Time`, INTERVAL '-1' MINUTE) FROM Live_Auctions WHERE ID='1'";
share|improve this answer
    
"Backticks" is the term you're looking for. – maiorano84 Oct 4 '12 at 3:23
    
Good to know, I did not know that =). Updating post. – Adam Plocher Oct 4 '12 at 3:24
    
Nothing happened. :( – Alec Oct 4 '12 at 3:25
    
Did you put it in your insert and select statements? It looks like you're using CURRENT_TIME twice. – Adam Plocher Oct 4 '12 at 3:26
    
Yah I did, but it doesn't do anything different. – Alec Oct 4 '12 at 3:28
//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."')";
share|improve this answer
    
No, it just gave me a bolded PHP error. – Alec Oct 4 '12 at 3:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.