tags:

views:

147

answers:

2

I have a strange bug where I call an insert query, it executes successfully (the row appears in the DB) but mysql_query returns false. It only returns false when a particular field contains an underscore or dash (or probably some other chars but these are the two I've run into so far).

"INSERT INTO Hoopoes (name, owner, dbuser, dbpass, package) VALUES "
                        ."('".$this->config['hname']."', '".$this->config['email']."','".$db_prefix.$db_username."','$db_userpass',"
                        ."'".$this->config['package']."')"

So this is the query. It fails when config['hname'] contains _ or -. I don't understand why. The row appears in the DB, but mysql_query still returns false. Any insight would be much appreciated

+1  A: 

You mus select the database after connect and before any query:

// Connect...
mysql_connect("server", "user", "pass");
// ...and select the database!
mysql_select_db("database");

// Now you're good to go. :)

You can use your INSERT query without select a database when you specify the schema, like this:

mysql_query("INSERT INTO `database`.`table` VALUES (...);
TiuTalk
ya, I did select it earlier in the script. this isn't the first DB call that's made. the config array gets pulled from the DB and a few other queries get made prior to this one. Either way, I threw a redundant mysql_select_db in there directly above the query and that seemed to shut it up. Thanks for the response!
wallacer
A: 

Hmm.. this was a strange one. The query worked and successfully inserted apparently without a database selected. I added a mysql_select_db call directly above the query, and now it works just the same, but the query returns true.

Strange

Thanks for the help!

wallacer