Submit article - Debt Consolidation - High Paying Adsense List - Bet365 bonus - Debt Consolidation

PDA

View Full Version : Cannot execute query error in PHP script


egdcltd
Oct 31st 2005, 1:18 pm
I am trying to construct a PHP script, but I can't even get the mysql_query to work. Every time I run the script below I keep getting the "Couldn't execute query" message. I can't get any further until I fix this, and I don't know what's causing it.

<?php
$username="username";
$password="password";
$database="database";

@mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM skt1_news ORDER BY DESC news_id LIMIT 0,3";
$result = @mysql_query($query)
or die ("Couldn't execute query");

?>

frankm
Oct 31st 2005, 2:58 pm
Your query (line 8) is missing a column name at ORDER BY something DESC

and you might want to extend your die() message to get a hint of what went wrong (line 10)

... die("Couldn't execute query: " . mysql_error());

egdcltd
Oct 31st 2005, 3:32 pm
Yes, that seems to have helped. Also news_id shouldn't have been in ' '. Thankyou.