• Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
justsomeguy

MySQL function expects parameter 1 to be resource, boolean given. Also "Headers already sent" error.

18 posts in this topic

Because so many people ask about error messages like this, and apparently don't want to figure out what the error message actually means, we'll make this a sticky topic to refer people back to when they ask about this. The error message takes this form: Warning: [some mysql function] expects parameter 1 to be resource, boolean given The function reporting the error could be any function which expects a MySQL result resource, including mysql_num_rows, mysql_fetch_array, mysql_fetch_assoc, etc. First, just to make this point: the mysql extension is old, deprecated, is missing features, and should not be used. You should be using mysqli instead, or PDO. http://www.php.net/manual/en/book.mysqli.phphttp://www.php.net/manual/en/book.pdo.php The error may be referring to a line that uses a mysql function that may look similar to this: $result = mysql_query($sql);$count = mysql_num_rows($result); The error would claim that mysql_num_rows expects a resource but got a boolean. That means that $result is a boolean value (true/false), not a MySQL result resource. So, what does that mean? The key is in the manual for mysql_query (you do look up PHP functions that you're using in the manual, right?): http://www.php.net/manual/en/function.mysql-query.php

Return ValuesFor SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
For the second group of queries, mysql_query always returns true or false to indicate if the query worked. For the first group of queries, including SELECT queries, it will return a resource if the query succeeded or boolean false if it failed. Since your error message is telling you that $result is a boolean, then that means your query failed. Like the example in the manual page for mysql_query shows, you use mysql_error to get the error message from MySQL:
$result = mysql_query($sql);if (!$result) {   die('Invalid query: ' . mysql_error());}

or, shorter: $result = mysql_query($sql) or die('Invalid query: ' .mysql_error()); Now you can figure out what the error is from MySQL, and fix your query. It will probably be useful to print out the query you're running so that you can see exactly what you're sending to MySQL.

8 people like this

Share this post


Link to post
Share on other sites

ok now i know how to fix those errors thanks, even tho i fine this post to be harsh lol but it helped :):good:

Share this post


Link to post
Share on other sites

I don't think it's harsh at all, it's a fact that a lot of people on here see an error message and immediately post a question about it instead of trying to figure out what it means. The reason I know this is because the error message is telling them exactly what the problem is, but they still ask about it. I've also seen people post a question about an error message like this, receive the answer, and later post a question about the exact same error message with the exact same solution, which indicates that they are not reading or understanding error messages. This is one such descriptive error message, it's specifically telling you that mysql_query returned a boolean and not a resource. It's not too much to expect people to look up the manual to find out why mysql_query would return a boolean instead of posting a question in a forum. That's what professional programmers do, research. It's what I try to teach here.

Share this post


Link to post
Share on other sites

not harsh at all. the same question has been asked twice in the past two days, and is probably the most frequently asked question about an error message (if they even have errors turned on) in the PHP forum

Share this post


Link to post
Share on other sites

im kool with harshness, and on my side, i only post an error if i really dont understand it at all, like the mysql_num_rows() error, i couldnt understand that error for months now, so i avoid using that function, till dont understand it full but i got the error fixed tho, which was pretty easy after reading this topic and the doc on php.net

Share this post


Link to post
Share on other sites

Warning: Cannot modify header information - headers already sent by (output started at /home/content/14/8709614/html/***********/*****/php/config.php:11) in /home/content/14/8709614/html/************/*****/index.php on line 61 Debug:Red colored text tell where (page and line) the output has started which is creating trouble. blue colored tells the calling php page and line Reason: Header can be sent once to the browser. If a header already sent you cant send another header later on the page. header get send when browser output something. Most commonly If header is already sent and you try to send another header using header() or try to set a cookie (cookies also sent with response headers) using setcookie() you will see this error. Causes:

  • Most commonly it happends when Your include files has white spaces or any outputs or any outputs or white spaces in the calling file itself.
  • When page is encoded as UTF-8 with Byte Order Mark (BOM)

Solution:

  • If it is problem with BOM you can change the file encoding to UTF-8 without BOM
  • Make sure include files/calling files does not have any outputs. you can omit the end php block of your include files at last line ?> php interpreter can assume on its own when the block ends.
  • It is usualy better to do Proccessing before you do any outputs to browser. but at last resort still in case it is not a option you can use php output buffering

Edited by birbal
6 people like this

Share this post


Link to post
Share on other sites

headers already sent error could found also on when we put session @ after outputting something right ?

Share this post


Link to post
Share on other sites

yes, as session id also sent as cookie and sent with header it will show same error.

Share this post


Link to post
Share on other sites

thankz :)

Edited by invisible_girl

Share this post


Link to post
Share on other sites

Not to be mean or anything, but we should definitely not show or even give the idea that using mysql_query is a good idea anymore. I know that you mention we should use PDO or mysqli, but why continue on to show them how to get errors using mysql_query. Someone should write about how to get errors and read errors using PDO as it is tends to be quiet unless you force it to tell you.

Share this post


Link to post
Share on other sites
Not to be mean or anything, but we should definitely not show or even give the idea that using mysql_query is a good idea anymore. I know that you mention we should use PDO or mysqli, but why continue on to show them how to get errors using mysql_query. Someone should write about how to get errors and read errors using PDO as it is tends to be quiet unless you force it to tell you.
This thread was made because of the amount of people that come to us asking about this particular error.

Share this post


Link to post
Share on other sites
This thread was made because of the amount of people that come to us asking about this particular error.
I acknowledge what you all are trying to do, and I am not trolling. I really just not a fan of correcting outdated deprecated code. You wouldn't want to fix something that you know will be on the next update or so. That makes me question why it is that we aren't fixing their bigger issue first. Let me try to explain with a pathetic analogy :Pleased: . If you had a problem with a small part of your car's muffler, and that part was recalled, wouldn't you want them to show you how to get a new muffler rather than to fix your old broken muffler? eh, I give up lol

Share this post


Link to post
Share on other sites

it always takes a while for what is deemed to be deprecated, actually become deprectated when servers, browsers, etc stop supporting it. but it takes many iterations of server software, browsers, etc for those features to get phased out. in the meantime, people will still be using these features, and as such, a reference for these features is still relevant. if in five years per se, people were still use mysql, then yeah, I'd say "yeah, get with the program", haha.

Share this post


Link to post
Share on other sites

The battle against the mysql extension is ongoing. There's no reason to use it anymore for anything, but as long as the tutorials on w3schools.com use it as an example (which they still do), it's hard for us to ignore it here. I would like it if they removed all references to mysql in their tutorials and used mysqli for the basic tutorials, with additional tutorials using PDO. I tried to pick my words carefully in the initial post, like capitalizing MySQL to try and imply that it is any function that deals with MySQL instead of the mysql extension specifically, but, like old versions of IE, the mysql extension is hard to ignore at this forum. I would prefer to see people who reply to questions about the mysql extension respond with information about mysqli though.

Share this post


Link to post
Share on other sites

Hello everyone,

 

Just a quick clarification... isn't something like the following suppose to give the "headers already sent" error? I tried the following and didn't get an error.

<?phpsession_start();header('location: http://www.google.com');?>

I read sometime ago that having session_start() and then have header() sometime after can cause the error. Thanks.

Edited by Don E

Share this post


Link to post
Share on other sites

As long as there are no echo statements and there's nothing outside <?php ?> tags then you won't get the error.

 

This would give you a headers already sent error

<?phpsession_start();// The following three line breaks are considered output// Headers cannot be sent after output is sent to the client.?>  <?phpheader('location: http://www.google.com');?>
1 person likes this

Share this post


Link to post
Share on other sites

Thanks for the clarification Foxy Mod. :good:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now