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.
You want to use mysql_query(), not mysql_db_query().
And why do you enclose all your variables in quotes?
Use mysql_query()
instead of mysql_db_query()
which is deprecated.
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
精彩评论