Page 1 of 2
You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 12:33 pm
by mayanktalwar1988
Code: Select all
<?php
$filename = "keywords.txt";
$filehandle = fopen($filename, 'w') or die("can't open file");
include("config.php");
$query="select * from downloads";
$result=mysql_query($query) or die(mysql_error());
$query1="update downloads set keyword=1 where release=1";
mysql_query($query1) or die(mysql_error());
while($word=mysql_fetch_array($result,MYSQL_BOTH))
{
if($word['release']==1)
{
$string=$string." ".$word['title'];
}
}
fwrite($filehandle, $string);
fclose($filehandle);
?>
the below line
Code: Select all
$query1="update downloads set keyword=1 where release=1";
is giving this error
Code: Select all
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 'release=1' at line 1
...whats wrong with update query?
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 12:42 pm
by andyhoneycutt
release is a reserved word. wrap tics around it:
Code: Select all
update downloads set keyword=1 where `release`=1
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:16 pm
by mayanktalwar1988
k now error gone away buts it not setting the keyword value to 1 where release=1
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:38 pm
by andyhoneycutt
run this, and let me know the result:
Code: Select all
SELECT COUNT(*) FROM downloads WHERE `release`=1;
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:39 pm
by mayanktalwar1988
your query gives 30
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:47 pm
by andyhoneycutt
is keyword an enum, or a char?
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:52 pm
by mayanktalwar1988
its an int
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:53 pm
by andyhoneycutt
ok, do this then:
Code: Select all
SELECT COUNT(*) FROM downloads WHERE keyword = 1;
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 1:59 pm
by mayanktalwar1988
right now value for the keyword column is null so this will give a zero..i checked it its a zero
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:06 pm
by andyhoneycutt
Could you give me a "SHOW CREATE TABLE downloads"?
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:08 pm
by mayanktalwar1988
i am not getting this there are 30 rows for which release has the value =1 but when i run this query
Code: Select all
update downloads set keyword=1 where 'release'=1
it says zero rows effetecd even when the value of rows in keyword column is zero
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:10 pm
by andyhoneycutt
Oh, use backticks as I showed above: ` not '
' is for values.
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:11 pm
by mayanktalwar1988
here it goes
Code: Select all
CREATE TABLE IF NOT EXISTS `downloads` (
`title` text,
`downloadlink` text,
`pagelink` text,
`category` text,
`release` int(1) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`keyword` int(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=376 ;
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:13 pm
by mayanktalwar1988
k i mistaken back ticks for single inverted commas sorry i wasted your time..thanks
Re: You have an error in your SQL syntax?
Posted: Tue Jun 15, 2010 2:14 pm
by mayanktalwar1988
ya its worked backticks worked sorry again