I am learning php and reading Kevin Yanks book.
I got to the first part of php - loaded up my page and immediately got:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource blah blah

I have checked the case in everything and they are all correct...
the code I copied from the book at that is generating this error is:

// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
  echo '<p>' . $row['password'] . '</p>';

can anyone help please

townders

Member Avatar for diafol

Post the whole code...

dont understand what yr saying plz explain

this is the whole code

$conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error');
if ($dbconn) {
  exit('<p>Unable to connect to the ' .
      'database server at this time.</p>');
}

// Select the jokes database
if (@mysql_select_db('members')) {
  exit('<p>Unable to locate the joke ' .
      'database at this time.</p>');
}

?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php
  
// Request the text of all the jokes
$result = @mysql_query('SELECT password FROM member');
if ($result) {
  exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
  echo '<p>' . $row['password'] . '</p>';
}

?>
</blockquote>
</body>
</html>
Member Avatar for diafol

this is the whole code

$conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error');
if ($dbconn) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}

// Select the jokes database
if (@mysql_select_db('members')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}

?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php

// Request the text of all the jokes
$result = @mysql_query('SELECT password FROM member');
if ($result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row . '</p>';
}

?>
</blockquote>
</body>
</html>

This looks a bit weird. You're asking for password data from all members, but then you're saying that you're outputting jokes? Anyway, Take away the '@' in front of the mysql_query because that turns off the error messages (which you'll need for successful debugging). Once you get things to work, put it back.

if ($result) {
  exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

This line seems to be your problem - "if the recordset exists, exit with an error message". Change it to this:

if (!$result) {
  exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.