PDA

View Full Version : Warning: mysql_fetch_array() expects parameter ...


ongik
05-12-2010, 10:44 PM
Hi, your video tutorial is excellent. I m learning your PHP, a beginners guide. Probably I made a stupid mistake along the line that I did not know.
Sorry for asking this beginner question, but I can't figar out where is the mistake. This is what I got and what is this mean?

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Test\dwc.php on line 7

I am using connTest.php, and I worked when I tested.
under "field2" on my is "field_2"

This is my coding:

<?php
require_once("Connections/connTest.php"); //database connection

/////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////1

echo $row['field_2']."<br>";

?>

Thank you for you help.

tux
05-13-2010, 07:59 AM
You can surpress the Warning by putting a @ sign before like this.


<?php
require_once("Connections/connTest.php"); //database connection

/////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = @mysql_fetch_array($result);//notice @ sign
///////////////////////////////1

echo $row['field_2']."<br>";

?>

ongik
05-13-2010, 05:39 PM
Thanks tux.
the warning is gone, but nothing showed up on the screen.
Sorry for the novice question.

davidj
05-13-2010, 07:11 PM
My Bad

When I made those tutorials I was very naive. There maybe reasons when you could use the suppressor but I think differently now. You should always try to find why you are getting the warning and sort it out.

First remove the @ from every line

echo the $result variable... see below


$query = sprintf("SELECT * FROM table1");

$result = mysql_query($query);

echo $result;


What does it output?