Jump to content

Need Help Resolving The Warning: Mysql_Query(): 4 Is Not A Valid Mysql-Link Resource In


eldan88

Recommended Posts

Hey,

 

It took to couple months to learn PHP and I am trying to extend my knowledge by designing my own ecommerce CMS.

 

I am having difficulties with the building blocks. When I try to run a mySQL query I get the following message:

 

"mysql_query(): 4 is not a valid MySQL-Link resource in"

 

What does this mean and how can I solve this. Btw my connection is successful to the DB.

 

Below is my cose

 

<?php
// Return data from the DB
$query = "SELECT * FROM ecommerce ";
$result = mysql_query($query,$connection);
if(!$result) {
die("mySQL DB read failed" . mysql_error());
}
//use the return data
while($return = mysql_fetch_array($result)) {
$return['category_name'];
}

?>
<?php mysql_close($connection); ?>

 

Any help is apperciated. Thanks!

Link to comment
Share on other sites

Where is your connection variable?

 

Hey,

 

Here is my connection variables located

 

<?php require_once("constants.php")// This has all the constants for the DB connection ?>
<?php
// First you make a connection with the database
$connection = mysql_connect(DB, username);
if (!$connection) {
die ( "Could not connect" . mysql_error());
}
// Second you delect which DB you want to work with
// You want to pass along the "handle to mysql_db_select"
$db = mysql_select_db(db_name, $connection);
if (!$db) {
die("Couldn't Select a DB" . mysql_error());
}
mysql_close($connection);

 

 

Below is my constant file

 

<?php
define("DB", "localhost");
define("username", "root");
define("db_name", "ecommerce");
?>

Link to comment
Share on other sites

Also, you're not using a password, for the root user? Seriously?

If, go set a password immediately. Even if it's just your development/test server.

 

Hey. This is just a testing website. It will never be deployed in a publicly, and there isnt any kind of sensitive data. Thats why there isn't any password set.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.