Jump to content

query error in php


dansk

Recommended Posts

i got this query in php

$result=mysql_query("SELECT * FROM Announ.jan WHERE Key =' " .date('d'). " '    ")or die(mysql_error());


and i get this error

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

Link to comment
https://forums.phpfreaks.com/topic/33872-query-error-in-php/
Share on other sites

ted, in this case, it seems the original use of date (ie, the function) is correct.

i believe "Key" is a reserved word. You should try and avoid using SQL reserved words, but if you want to carry on in this case, enclose the 'Key' with backticks (` - normally the key directly to the left of the number 1).

Also, remove the spaces between the single and double quote:

[code]
<?php
$result=mysql_query("SELECT * FROM Announ.jan WHERE `Key` = '" .date('d'). "'") or die(mysql_error());
?>
[/code]

that should help
cheers
Link to comment
https://forums.phpfreaks.com/topic/33872-query-error-in-php/#findComment-158963
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.