user776530
user776530

Reputation: 133

mysql command not executing using php

For some reason my sql query is not executing and the error message is not printing in php. Here is the code:

    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql = "DELETE FROM data WHERE id='".$_GET['id']."'";
    echo $sql;
    $result=mysql_db_query($sql);
    if(!$result) {
        $msg = "ERROR: ". mysql_error();
        echo $msg;
    }

I know its vulnerable for sql injection right now but im going to fix that after i get it working. Also, if i copy what $sql prints and paste it into phpmyadmin it works and it does go into the if statement.

Upvotes: 0

Views: 536

Answers (3)

undone
undone

Reputation: 7888

http://www.php.net/manual/en/function.mysql-db-query.php

mysql_db_query

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

instead use mysql_query

Upvotes: 0

wonk0
wonk0

Reputation: 13962

You want to use mysql_query(), not mysql_db_query().

And why do you enclose all your variables in quotes?

Upvotes: 2

ldiqual
ldiqual

Reputation: 15375

Use mysql_query() instead of mysql_db_query() which is deprecated.

Upvotes: 1

Related Questions