[Solved] MySQL Errors!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

[Solved] MySQL Errors!

Post by Devnull »

I got a script called view.php which extracts details from a database and displays them. The script is as follows:

Code: Select all

//select the table
$dresult = mysql_query("select * from informes");

//grab all the content
while($r=mysql_fetch_array($dresult))
{
  
   $date = $r["date"];
   $city = $r["city"];
   $area = $r["area"];
   $street = $r["street"];
   $positiont = $r["positiont"];
   $unitn = $r["unitn"];
   $unitl = $r["unitl"];
   $incident = $r["incident"];
   $property = $r["property"];
   $sandiamo = $r["sandiamo"];
   $sbbg = $r["ssbg"];
   $stelxo = $r["stelxo"];
   $observations = $r["observations"];
 	
	print '<table width="100%"  border="0" cellspacing="2" cellpadding="1">';
	print '  <tr>';
	print '    <td><strong>Fecha:</strong></td>';
	print '    <td colspan="3">$date</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Area:</strong></td>';
	print '    <td colspan="3">$area</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Cuidad:</strong></td>';
	print '    <td colspan="3">$city</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Direcci&oacute;n:</strong></td>';
	print '    <td colspan="3">$street</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Posici&oacute;n:</strong></td>';
	print '    <td colspan="3">$positiont</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>N&ordm; Soporte/Letra: </strong></td>';
	print '    <td colspan="3">$unitn</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Incidente:</strong></td>';
	print '    <td colspan="3">$unitl</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Propiedad:</strong></td>';
	print '    <td colspan="3">$property</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><strong>Pegatinas:</strong></td>';
	print '    <td><strong>Andiamo</strong></td>';
	print '    <td><strong>BBG</strong></td>';
	print '    <td><strong>Telxo</strong></td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td></td>';
	print '    <td>$sandiamo</td>';
	print '    <td>$sbbg</td>';
	print '    <td>$stelxo</td>';
	print '  </tr>';
	print '  <tr>';
	print '    <td><p><strong>Observaciones:</strong></p>';
	print '    </td>';
	print '    <td colspan="3">$observations</td>';
	print '  </tr>';
	print '</table>';
}
I keep getting the following error on Line 17:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/view.php on line 17
This is Line 17:

Code: Select all

while($r=mysql_fetch_array($dresult))
What's wrong in my code?
Last edited by Devnull on Tue Aug 09, 2005 7:32 am, edited 1 time in total.
User avatar
Ashiro
Forum Newbie
Posts: 8
Joined: Wed Jun 22, 2005 5:01 am
Contact:

Post by Ashiro »

At a guess I'd say that your query $dresult = mysql_query("select * from informes"); is not executing correctly and your not getting a valid result.
In your situation I'd recommend the following steps for error diagnosis:

1. echo the sql command.
2. echo the $dresult value.
3. place the sql command as it is echoed into the SQL part of your PHPMyAdmin (if you have this running - which I recommend you do) to test if it works.

I think you'll find PHPMyAdmin will give you a MySQL error message as thats where I think the problem lies.

I'd also suggest placing error checking on your queries like so:

Code: Select all

$dresult = mysql_query("select * from informes") or die("DB error: ".mysql_error());
That way your script will die and report the error before it attempts to extract data using the fetch_array function.
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

Thanks, I forget about using the mysql error function!
Post Reply