0

Im trying to display all raw in my family_spouse table

code

      <?php 



    $query = "SELECT FROM family_spouse";
    $result = mysql_query ($query);

    echo "<table border='1'>
    <tr>
    <th>Family Type</th>
    <th>Name</th>
    <th>Gender</th>
    </tr>";

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['spouse_type'] . "</td>";
    echo "<td>" . $row['spouse_name'] . "</td>";
    echo "<td>" . $row['spouse_gender'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    ?>

when i run the code, this error appear Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\eprofile\dashboard.php on line 598

line 598

while($row = mysql_fetch_array($result))
afifi
  • 87
  • 1
  • 4
  • 12
  • You're missing an * after `SELECT`. It should be `"SELECT * FROM family_spouse`. Also, `mysql` is deprecated. It's development status is "Maintenance Only" it will probably not be supported in the near future. http://www.php.net/manual/en/mysqlinfo.api.choosing.php – Jacques ジャック Oct 08 '13 at 02:06

5 Answers5

1

The error is in your query, which probably should be:

$query = "SELECT * FROM family_spouse";

You'd know this if you bothered to check the return value of your query.

Assuming you have connected to your database properly you should do this:

$query = "SELECT * FROM family_spouse";
$result = mysql_query($query) or die(mysql_error());

Note that mysql_*() is deprecated, and you should be using mysqli_* or PDO.

0

The error you're receiving means that the SQL query you're executing resulted in an error:

$query = "SELECT FROM family_spouse";

You didn't list any columns here; try updating this line to:

$query = "SELECT * FROM family_spouse";

To view the actual error (in the event that you receive additional ones in the future), you can use mysql_error(); You can combine your query with mysql_error() like:

if ($result = mysql_query ($query)) {
    // display the results
} else {
    echo 'Error: ' . mysql_error();
}

Side note (not answer specific):
You should consider using the MySQLi or PDO libraries instead of the outdated/unsupported mysql_ methods.

newfurniturey
  • 35,828
  • 9
  • 90
  • 101
0

Your query is failing and therefore not producing a query resource, but instead producing FALSE.

Change

$query = "SELECT FROM family_spouse";

to

$query = "SELECT * FROM family_spouse";

Note: mysql_() function is deprecated, and you should be using mysqli_ or PDO.

Tamil Selvan C
  • 19,232
  • 12
  • 49
  • 68
0

I think what you want for the query is

SELECT * FROM family_spouse

(note the added asterisk)

Joshua Nelson
  • 591
  • 2
  • 10
0

Update the query to this!

$query = "SELECT * FROM family_spouse";

The * means "ALL". So, select ALL from family_spouse!

Dane Caswell
  • 201
  • 5
  • 9