Cannot execute query error in PHP script

Discussion in 'PHP' started by egdcltd, Oct 31, 2005.

  1. #1
    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");
    
    ?>
    PHP:

     
    egdcltd, Oct 31, 2005 IP
  2. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #2
    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());
     
    frankm, Oct 31, 2005 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, that seems to have helped. Also news_id shouldn't have been in ' '. Thankyou.
     
    egdcltd, Oct 31, 2005 IP