Page 1 of 1

mysql_query problems...

Posted: Fri Mar 20, 2009 11:01 am
by flemingmike
this is my new code, its on line 87:

Code: Select all

mysql_query("DELETE FROM findamatch WHERE NOW() - 030000 > $timestamp") or die(mysql_error());

This is the error i recieve:

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 '' at line 1


here is my whole code:

Code: Select all

<?
 
include("./includes/incglobal.php");
 
global $config;
 
 
 
$out[body].="<center>  
<br />
<table border='0' width='95%' cellspacing='1' cellpadding='2' bgcolor='#000000'>
   <tr bgcolor='$config[altcolora]'>
      <td colspan='7' background='$config[bg]'>
         <B> &nbsp;  &nbsp;  &nbsp; Ready to Play</B> 
      </td>
   </tr>
   <tr bgcolor='$config[altcolorb]'>
           <td background='/images/td_bg2.gif'>
         <B><center>Challenger</B>
      </td>
      <td background='/images/td_bg2.gif'>
         <B><center>Game</B>
      </td>
     <td background='/images/td_bg2.gif'>
         <B><center>Rules</B>
      </td>
      <td background='/images/td_bg2.gif'>
         <B><center>Max Bet</B>
      </td>
           <td background='/images/td_bg2.gif'>
         <B><center>Challenge</B>
      </td>
      <td background='/images/td_bg2.gif'> 
         <B>
<center>Contact</B>
      </td>
</tr>";
 
 
 
 
$fam=mysql_query("SELECT id,clan,rules,month,day4,year,hour,min,ampm,timezone,teamid,ladder,maxbet,aim,email,yim,timestamp FROM findamatch ORDER BY timestamp");
while(list($id,$clan,$rules,$month,$day4,$year,$hour,$min,$ampm,$timezone,$teamid,$ladder,$maxbet,$aim,$email,$yim,$timestamp)=mysql_fetch_row($fam)){
 
 
 
 
 
$icq2 = "<img src='./images/icq.gif' align='bottom'>";
$aim2 = "<a href='aim:goim?screenname=$aim&message=Hello+Are+you+there?'><img src='./images/aim.gif' border='0'></a>";
$email2 = "<a href='mailto:$email'><img src='./images/email.gif' border='0'></a>";
$edit = "<form method='post' style='margin-bottom: 0'><input type='hidden' name='find[teamid]' value='$teamid'>
<input type='hidden' name='act' value='edit'><input type='hidden' name='pid' value='$id'><input type='image' src='./images/edit.gif' name='submit'></form>";
$yim2 = "<a href='http://edit.yahoo.com/config/send_webmesg?.target=$yim&.src=pg'><img src='./images/yahoo.gif' border='0' align='absmiddle'></a>";
 
if ($aim == "") {
$aim2 = "";
}
if ($aim == "0") {
$aim2 = "";
}
if ($yim== "") {
$yim2 = "";
}
if ($yim == "0") {
$yim2 = "";
}
 
$out[body].="
<tr bgcolor='$config[altcolora]' align='center'>
            <td><center><a href='./stats.php?account=$teamid'>$clan</a></td>
            <td><center>$ladder</td>
            <td><center>$rules</td>
            <td><center>$$maxbet</td>
            <td><center><a href='./challenge.php?login[cid]=$teamid'>Challenge</a></td>
      <td><table border='0'>
   <tr><td align='center'>
        <center> $email2 <br><b>PS3 Name:</b> <a href='./stats.php?account=$teamid'>$aim</a><br><b>XBox360 Name:</b> <a href='./stats.php?account=$teamid'>$yim</a></center></td></tr>
</table></td>
</tr>
"; 
$count++;
}
 
mysql_query("DELETE FROM findamatch WHERE NOW() - 030000 > $timestamp") or die(mysql_error());
 
if($count == 0){
$out[body].="
<tr bgcolor='$config[altcolora]'>
      <td colspan='7'>
         <center>There is currently nobody looking for a game.</center>
      </td>
</tr>";
}
 
 
 
 
$out[body].="</table>";
 
$out[body].="<br /><br />";
 
include("$config[html]");
 
 
 
?>

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 11:08 am
by Christopher
Print your query so you can see what your SQL actually is:

Code: Select all

$sql = "DELETE FROM findamatch WHERE NOW() - 030000 > $timestamp";
echo "SQL=$sql";
mysql_query($sql) or die(mysql_error());

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 11:10 am
by flemingmike
does it matter where i put this

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 11:21 am
by flemingmike
here is my error:

SQL=DELETE FROM findamatch WHERE NOW() - 030000 > 1237566011

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 11:36 am
by temidayo
flemingmike wrote:here is my error:
SQL=DELETE FROM findamatch WHERE NOW() - 030000 > 1237566011
What are you trying to achieve with this query?

You might need to convert NOW() to timestamp format before using it in the calculation!

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 11:53 am
by flemingmike
im trying to remove all entries once the timestamp reaches 3 hours or older

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 12:15 pm
by temidayo
Try using UNIX_TIMESTAMP() like this:

Code: Select all

SQL=DELETE FROM findamatch WHERE UNIX_TIMESTAMP() - 030000 > 1237566011

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 12:24 pm
by Eran
Notice that you should be passing 3 hours as seconds, as I showed you in the previous post you opened. 030000 is not 3 hours in seconds, 3600 * 3 = 10800 is. Aside from that, there is no reason the query shouldn't work. dump the contents of $timestamp using var_dump() and post the results here.

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 12:34 pm
by flemingmike
error on line 7. same line i put that code on...

Re: mysql_query problems...

Posted: Fri Mar 20, 2009 2:10 pm
by temidayo
flemingmike wrote:error on line 7. same line i put that code on...
I guess that was in response to my code. That code was syntactically (PHP) wrong but the idea I was
trying to pass across is correct.
pytrin wrote: 030000 is not 3 hours in seconds, 3600 * 3 = 10800 is.
If that is correct then running the follow SQL will give you what you need:
SELECT UNIX_TIMESTAMP() - 10800 - This will return the time 3 hours ago.

Applying that to your case should be:

Code: Select all

$sql = "DELETE FROM findamatch WHERE UNIX_TIMESTAMP() -  10800 > $timestamp";