Jump to content

HELP: mysql_query(): supplied argument is not a valid MySQL-Link resource


library

Recommended Posts

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!

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.