<?php
$hostname = "localhost";
$password = "password";
$database = "reports";
$username = "your_name";
//connection to the database
$con = mysql_connect($hostname, $username, $password)
or die("Connecting to MySQL failed");
//select a database to work with
$selected = mysql_select_db("report", $con)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT id, stations, title, detail from insert");
//fetch tha data from the database
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "ID:".$row{'Id'}. "Station:".$row{'Stations'}. "Title:".$row{'Title'}. "Detail:".$row{'Detail'}."<br>";
}
//close the connection
mysql_close($con);
?>
mysql_fetch_array() expects parameter 1 to be resource, boolean give
Started by CiszLaserna, Feb 03 2013 01:02 PM
6 replies to this topic
#1
Posted 03 February 2013 - 01:02 PM
Kinda new to php im using array to post the inbox of an email application but it seems i got an error this code here:
#2
Posted 03 February 2013 - 01:04 PM
You need to check for errors. See the link in my signature on debugging SQL.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#3
Posted 03 February 2013 - 01:15 PM
error is this
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\report\inbox.php on line 23
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\report\inbox.php on line 23
Edited by CiszLaserna, 03 February 2013 - 01:17 PM.
#4
Posted 03 February 2013 - 02:41 PM
You need to check for errors. See the link in my signature on debugging SQL.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#5
Posted 03 February 2013 - 03:56 PM
If I had a penny for every time someone asked about this error on this forums, I would be rich.
I don't mean to be rude.
The error message is actually very precise and helpful. mysql_fetch_array() is being called with a boolean value where a resource is expected. If you look at the documentation for mysql_query(), you will see that it returns FALSE on failure, which is a boolean. This value is stored in $result, which is then passed to mysql_fetch_array(). So, an error occurs with your SQL query. Perhaps you made a spelling mistake or perhaps the word "insert" is not allowed; I am actually not sure. Anyways, you can check the error like this:
Also, please consider using MySQLi or PDO instead as the mysql_* extension is deprecated. I am merely name dropping here, so please take the time to read about these.
The error message is actually very precise and helpful. mysql_fetch_array() is being called with a boolean value where a resource is expected. If you look at the documentation for mysql_query(), you will see that it returns FALSE on failure, which is a boolean. This value is stored in $result, which is then passed to mysql_fetch_array(). So, an error occurs with your SQL query. Perhaps you made a spelling mistake or perhaps the word "insert" is not allowed; I am actually not sure. Anyways, you can check the error like this:
$result = mysql_query("SELECT id, stations, title, detail from insert") or die(mysql_error());Also, please consider using MySQLi or PDO instead as the mysql_* extension is deprecated. I am merely name dropping here, so please take the time to read about these.
Blogging about PHP and other programming related subjects at CodingExplained.com.
#6
Posted 03 February 2013 - 04:12 PM
The problem is the use of "insert" but OP needs to learn to capture mysql errors.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#7
Posted 03 February 2013 - 04:31 PM
opps did na see. thank you
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











