Jump to content

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


Recommended Posts

Hi everyone,

 

I'm getting this error and I don't know why.

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\users\include\database.php on line 16

 

I am proberly missing something.

 

Here is the code that I'm referring it from

$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$user = $_POST['user'];
$pass = $_POST['pass'];

$sql = "INSERT INTO users (firstname, lastname, email, username, password)";
$sql .= " VALUES ('$first', '$last', '$email', '$user', '$pass')";
$result = $database->insert_user($sql);

 

This is what I'm sending it to:

function query($sql){
	$result = mysql_query($sql,$this->connection);
	$this->confirm_query($result);
	return $result;
}

private function confirm_query($result){
	if(!$result){
		die("Database query failed: " . mysql_error());
	}
}

 

Thanks for your help,

 

tecmeister.

I had that originally, but I change it to the tutorial way and I still have the same warning.

Is there something wrong with the $sql variable?

 

Well what's the warning say?  The SQL syntax looks valid to me...  Maybe you should try to echo out '$sql' to see the string that's actually being passed to your function.

I have also tried that and print.

This is what I get.

INSERT INTO users (firstname, lastname, email, username, password) VALUES ('Johnny', 'McCaffery', 'notanotherperson@hotmail.com', 'tecmeister', 'password').

 

Can you see and error?

 

Thanks for your help, much appreciated

 

temeister.

Here is the warning:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\users\include\database.php on line 16

 

That line is this:

$result = mysql_query($sql,$this->connection) or die(mysql_error());

 

When I take away $this->connection.

It cant connect to the database.

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\users\include\database.php on line 17

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\users\include\database.php on line 17

Access denied for user 'ODBC'@'localhost' (using password: NO)

<?php
class mysqldatabase{

private $connection;

function __content(){
	$this->open_database;
}

function open_database(){
	$this->connection = mysql_connect("localhost","teci","********")or die("Connect Error".mysql_error());
	$this->connection = mysql_select_db("users")or die("Select Database Error".mysql_error());
}

function query($sql){
	$result = mysql_query($sql,$this->connection) or die(mysql_error());
	return $result;
}


}
$database = new mysqldatabase;
return $database;
?>

Where is the private function confirm_query()?  You need to post consistent code.

 

Try using this class:

 

class mysqldatabase{

   private $connection;
   
   /* Class constructor */
   function __construct(){
      $this->connection = mysql_connect("localhost","teci","********")or die("Connect Error".mysql_error());
      $this->connection = mysql_select_db("users")or die("Select Database Error".mysql_error());
   }
   
   function query($sql){
      $result = mysql_query($sql,$this->connection) or die(mysql_error());
      return $result;
   }
   
}

$database = new mysqldatabase;
return $database;
?>

 

Try this:

 

$sql = "INSERT INTO `users` (`firstname`, `lastname`, `email`, `username`, `password`)";

 

I think there is a conflict between the field password and MySQL function PASSWORD. So, its better to enclose all the MySQL table name and field names with backquote (`) character in order to avoid the conflict.

 

Hope this will help.

 

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.