library Posted March 5, 2010 Share Posted March 5, 2010 I keep tinkering around, trying to fix this error: mysql_query(): supplied argument is not a valid MySQL-Link resource Here is the code in question: $dbhost = 'localhost'; $dbuser = 'xxxx'; $dbpass = 'xxxx'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'books'; mysql_select_db($dbname); $query = "INSERT INTO bookresponses (name, email, bridge, beatles, catch, memoriam, wild, matarese, esebius, french, wave, link, body, earth, questions " . "VALUES ('$name', '$email', '$bridge', '$beatles', '$catch', '$lord', '$wild', '$lud', '$church', '$french', '$wave', '$link', '$body', '$earth', '$questions')"; $result = mysql_query($conn,$query) or die('Error querying database.'); mysql_close($conn); Thanks for any help and suggestions in advance! Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/ Share on other sites More sharing options...
trq Posted March 5, 2010 Share Posted March 5, 2010 Your connection is failing for whatever reason. Take a look at mysql_error to see if you can't find out why. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021823 Share on other sites More sharing options...
PFMaBiSmAd Posted March 5, 2010 Share Posted March 5, 2010 More importantly, the second parameter in a mysql_query() statement is the connection. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021824 Share on other sites More sharing options...
Tazerenix Posted March 5, 2010 Share Posted March 5, 2010 yea, its mysql_query(query, connection) But mysqli_query is (connection, query) as far as i remember Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021827 Share on other sites More sharing options...
library Posted March 5, 2010 Author Share Posted March 5, 2010 I switched that section to the code to: $result = mysql_query($query, $conn) or die('Error querying database.'); However, now I have the error: Error querying database. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021829 Share on other sites More sharing options...
PFMaBiSmAd Posted March 5, 2010 Share Posted March 5, 2010 If you output the query statement in $query and output mysql_error() as part of your error reporting, it will help by letting you see what the query actual is and by indicating what mysql found wrong with the query. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021832 Share on other sites More sharing options...
library Posted March 5, 2010 Author Share Posted March 5, 2010 I am really struggling here. I've changed the code to: $dbhost = 'localhost'; $dbuser = 'xxxx'; $dbpass = 'xxxx'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'boompah1_books'; mysqli_select_db($dbname); $query = "INSERT INTO bookresponses (name, email, bridge, beatles, catch, memoriam, wild, matarese, esebius, french, wave, link, body, earth, questions " . "VALUES ('$name', '$email', '$bridge', '$beatles', '$catch', '$lord', '$wild', '$lud', '$church', '$french', '$wave', '$link', '$body', '$earth', '$questions')"; $result = mysqli_query($conn, $query) or die('Error querying database.'); mysql_close($conn); But now I get: Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in /home/boompah1/public_html/librarylasso.com/books.php on line 34 Error querying database. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021835 Share on other sites More sharing options...
trq Posted March 5, 2010 Share Posted March 5, 2010 Take a look at the man page for mysqli_select_db, it expects your database connection. Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1021836 Share on other sites More sharing options...
Tazerenix Posted March 5, 2010 Share Posted March 5, 2010 Stick with mysql for now not mysqli, because you need to enable the mysqli extension in php.ini if you want to use it. And in mysqli_select_db() its $conn, $dbname Plus In your query, make it mysql_query($query, $conn) or die(mysql_error()); then it will tell you what is happening wrong in your queries Quote Link to comment https://forums.phpfreaks.com/topic/194218-help-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1022156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.