Warning: mysql_result() expects parameter 1 to be resource, boolean given
The problem is that mysql_query()
is returning a boolean instead of a result resource. There are two reasons this can happen:
- You performed query that returns success/fail instead of a result set (e.g.
UPDATE
) - Your query failed
In your case the query failed. The reason it failed is because you have escaped the back ticks in the PHP string where you did not need to.
Your lines look like this:
$siteTitle = mysql_result(mysql_query("SELECT \`siteTitle\` FROM siteSettings"), 0);
When they should simply be this:
$siteTitle = mysql_result(mysql_query("SELECT `siteTitle` FROM siteSettings"), 0);
Now, some side notes:
- Don't write new code that uses the
mysql_*
functions. They are deprecated and will eventually be removed from PHP. Use MySQLi or PDO instead (I personally recommend PDO, YMMV) - Nesting database functions in this way is not a particularly good way to write your code. It is much better to check the errors explicitly after every function call.
For example:
$result = mysql_query("SELECT somecol FROM sometable");
if (!$result) {
// Handle error here
}
// Now process the result
- You should quote either all identifiers, or none, in your queries (preferably all). Quoting only some makes it harder to read.
E.g.
SELECT `siteTitle` FROM `siteSettings`
Warning: mysql_result() expects parameter 1 to be resource, string given in
$search = mysql_query("SELECT `patData` FROM `reportData` WHERE id = 2");
if (!$search) {
die('Could not query:' . mysql_error());
}
echo mysql_result($search, 0);
The problem is that mysql_query() is may be returning a Boolean instead of a result resource. There are two reasons this can happen:
- You performed query that returns success/fail instead of a result set.
- Your query failed.
Notes :
- Don't write code that uses the mysql_* functions. They are deprecated and will eventually be removed from PHP.
- Use MySQLi or PDO instead.
mysql_free_result() expects parameter 1 to be resource
You can't free the result of an INSERT
query, since you can't free a boolean.
Related Topics
Get the First or Last Friday in a Month
Bad Request. Connecting to Sites via Curl on Host and System
Laravel Checking If a Record Exists
How to Handle User Input of Invalid Utf-8 Characters
Using Wget to Run a Cronjob PHP
How to Paginate a Merged Collection in Laravel 5
How to Parse a CSV File to Grab the Column Names First Then the Rows That Relate to It
Laravel 4 Removing Public from Url
Foursquare API for Venue User Image Error
Scale Image Using PHP and Maintaining Aspect Ratio
How to Find Number of Mondays or Tuesdays Between Two Dates
Cannot Send Session Cookie - Headers Already Sent
PHP Composer Update "Cannot Allocate Memory" Error (Using Laravel 4)
Getting Relative Path from Absolute Path in PHP
How to Set an Arrays Internal Pointer to a Specific Position? PHP/Xml