This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Warning: mysql_query(): 3 is not a valid MySQL-Link resource
I don't know why the $GUconnection resource isn't working on queries since I set it up as a global variable. The db connection is
$GUconnection = mysql_connect(serverip, username, password);
#mysql_select_db(dbname, $GUconnection) or die('Cannot connect to the database.');
The following query is located in an include file that is included in the file containing the mysql connection above:
global $GUconnection;
$GUresult = mysql_query("SELECT field FROM `tablename` WHERE field = 'hey' LIMIT 1", $GUconnection);
if(mysql_num_rows($GUresult)) {
$GUfile = mysql_fetch_assoc($GUresult);
}
The errors I got where
Warning: mysql_query(): 3 is not a valid MySQL-Link resource in /home/ on line 49
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ on line 50
If I don't have the include and just paste the query directly underneath the connection then it works. What seems to be the problem?
Feel the power of google.
While writing your question on SO brings you no help, exact error message pasted into google's search box finds you complete solution. In much less time.
The connection may fail, so you should check for connection errors.
Related
This question already has an answer here:
PHP connection error with the database [closed]
(1 answer)
Closed 8 years ago.
I keep getting this error each time I run my .php page
It is supposed to show images taken from the server.
This page does show all the images but also error which is:
"Warning: mysqli_select_db() expects parameter 1 to be mysqli, string
given in F:\users\1203158\httpdocs\Adventure_Sports\gallery.php on
line 79 "
I do not understand how to eliminate this error
You presumably have:
$link = mysqli_connect( ... );
And my guess is you're doing:
mysqli_select_db("database_name");
That's how it was done with mysql_select_db, but with mysqli_, you have to pass the connection handler.
mysqli_select_db($link, "database_name");
The error is telling you that it's expecting a mysqli object (the connection handler) but is getting a string (the database name).
This question already has answers here:
Warning: mysql_query(): 3 is not a valid MySQL-Link resource
(4 answers)
Closed 9 years ago.
I am new to programming and following online tutorial.
I got an error please help.
Connected successfully
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/divitiae.net.co/make_my_tables.php on line 22
below is line 22
include_once("php_includes/db_connect.php");
$query = mysql_query($db_connect, $tbl_users);
if ($query === TRUE) {
echo "<h3>user table created OK :) </h3>";
} else {
echo "<h3>user table NOT created :( </h3>";
}
The error you are getting means that the $db_connect variable you are passing to the mysql_query function is not a MySQL connection object, as would be returned by the mysql_connect function.
Your php_includes/db_connect.php should contain something like:
$db_connect = mysql_connect('hostname', 'username', 'password');
mysql_select_db('databasename');
This will connect to the database on server hostname using the username and password provided. It then selects the database databasename as the database to perform operations on.
Warning!
You really, really, REALLY should not use the mysql_* set of functions because they are deprecated and you should use either the mysqli_* functions or implement PDO, as those are more flexible, safer, supported, and have better features.
This question already has an answer here:
Should we ever check for mysqli_connect() errors manually?
(1 answer)
Closed 2 years ago.
How do you prevent a connection error if, for example, the database name is invalid, for the given code below?
$mysql = new mysqli('localhost', 'user', 'pass', 'wrongdatabase');
if($mysql->connect_errno)
die($mysql->connect_error);
The if statement will output the right error message, but there will still be a warning sent from the first line, which says
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (42000/1049): Unknown database 'wrongdatabase' in C:\wamp\www\example.php on line 14
I know with PDO you would simply wrap it in a try/catch block, but how to do it with MySQLi?
The answer here was incorrect and outdated. A more recent answer to this question can be found here
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
I am receiving the following errors
Warning: mysql_query()
[function.mysql-query]: Access denied
for user 'anticub1'#'localhost' (using
password: NO)
Warning: mysql_query()
[function.mysql-query]: A link to the
server could not be established
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
When I submit the form everything goes into the database so I am not sure why I am getting that error...
<?php
$submit=$_POST['submit'];
$text=$_POST['text'];
if ($submit) {
$connect = mysql_connect("localhost","anticub1_shout","root12")
or die("could not connect");
mysql_select_db("anticub1_shoutbox") or die("could not find the db");
mysql_query("INSERT INTO comments VALUES ('','$text')");}
$query = mysql_query("SELECT * FROM comments");
while ($row = mysql_fetch_assoc($query)) {
$post = $row["posts"];
echo "$post"."<br>";
}
?>
The warning:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'anticub1'#'localhost' (using password: NO)
Is NOT produced by your example script! because you provide a password there and its an other username.
$connect = mysql_connect("localhost","anticub1_shout","root12")
Conclusion: You are searching at the wrong place. Search trough all your code for mysql_connect("localhost","anticub1")
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
$query = "SELECT UniqueID FROM configuration";
$result = mysql_query($query)or die(mysql_error());;
while($row = mysql_fetch_assoc($result)) { }
throwing exception as
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\ehp\hello.php on line 10
That's slightly confusing, since this sort of thing is usually caused by an SQL error, however the line ..or die(mysql_error()); should have picked that up. Check the contents of your loop that you're not overwriting the $result variable.