Jump to content

SELECT from db Error


Iceman512

Recommended Posts

Hi everybody,

I cannot get the following script to retrieve anything from my database. I am getting the traditional error; "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ...".

I have been checking the db connection values and db name for the last several hours, eventually I copied them from the database itself, so I'm pretty sure there are no errors there. Any suggestions would be helpful.

[code]
<?php
$dbhost = 'host';
$dbuser = 'database_user';
$dbpass = 'database_password';
$dbname = 'database_name';

$con = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$con)
  {
  exit('Error! Could not connect: ' . mysql_error());
  }
 
mysql_select_db($dbname, $con);

$result = mysql_query("SELECT count(*) FROM table");
if ($result <= "1")
  {
  echo "The database is currently empty";
  }
 
$result = mysql_query("SELECT id, description, cost_inc_vat, sale_inc_vat, model FROM table ORDER BY id DESC");
while($row = mysql_fetch_array($result));
{
?>
<table cellpadding="0" cellspacing="0" align="center" width="100%">
<tr><th id="css" colspan="2" align="left">Items In Database</th></tr>
<tr><td>&nbsp;</td></tr>
<tr>
  <td><font id="css"> <?php echo $row['description']; ?> </font></td>
  <td><font id="css"> <?php echo $row['cost_inc_vat']; ?> </font></td>
  <td><font id="css"> <?php echo $row['sale_inc_vat']; ?> </font></td>
  <td><font id="css"> <?php echo $row['model']; ?> </font></td>
</tr>
</table>
<?php
}
mysql_close($con);
?>
[/code]

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/35949-select-from-db-error/
Share on other sites

[code=php:0]<?php
$dbhost = 'host';
$dbuser = 'database_user';
$dbpass = 'database_password';
$dbname = 'database_name';

$con = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$con)
  {
  exit('Error! Could not connect: ' . mysql_error());
  }
 
mysql_select_db($dbname, $con);

$result = mysql_query("SELECT count(*) FROM table");
if ($result <= "1")
  {
  echo "The database is currently empty";
  }
 
$result = mysql_query("SELECT id, description, cost_inc_vat, sale_inc_vat, model FROM table ORDER BY id DESC");
while($row = mysql_fetch_array($result))
{
echo '<table cellpadding="0" cellspacing="0" align="center" width="100%">
<tr><th id="css" colspan="2" align="left">Items In Database</th></tr>
<tr><td>&nbsp;</td></tr>
<tr>
  <td><font id="css"> '.$row['description']'. </font></td>
  <td><font id="css"> '. $row['cost_inc_vat'].' </font></td>
  <td><font id="css"> '.$row['sale_inc_vat'].' </font></td>
  <td><font id="css"> '.$row['model'].'</font></td>
</tr>
</table>';

}
mysql_close($con);
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35949-select-from-db-error/#findComment-170495
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.