SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Error
-
May 22, 2004, 23:51 #1
- Join Date
- May 2004
- Location
- Nepal
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Error
I usually get the following when trying to connect:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/raazz053/public_html/Product_Details.php on line 186
====================================================================
<?
$sql=mysql_query("Select Title from tblMain where Id=$a_row[McatId]");
$amyrow=mysql_fetch_array($sql); ---error line 186
?>
Help!!
-
May 22, 2004, 23:56 #2
- Join Date
- Jul 2003
- Location
- Newberg, Oregon
- Posts
- 422
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
try this,
PHP Code:$sql=mysql_query("Select Title from tblMain where Id = '$a_row[McatId]'");
Codyrobert.com - Designer and Developer
-
May 23, 2004, 03:30 #3
- Join Date
- May 2004
- Location
- Norway, Oslo
- Posts
- 85
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi nuju_sj,
Have you tried to add the mysql_error() function after mysql_query?
PHP Code:$sql=mysql_query("Select `Title` FROM `tblMain` WHERE `Id` = '$a_row[McatId]'") or die(mysql_error());
-
May 23, 2004, 05:00 #4
- Join Date
- Aug 2002
- Location
- Burpengary, Australia
- Posts
- 4,495
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
It's easier to find errors if you lay your code out properly and make up some nice SQL error handler function
PHP Code:function mysql_die() {
global $sql;
echo '<b>Oops, an error has occurred and here\'s why:</b><br />
<blockquote>' . mysql_error() . '</blockquote><br /><br />
<b>Offending SQL:</b><br />
<pre>' . $sql . '</pre>';
return true;
}
$sql = "select
title
from tblmain
where
id = '{$a_row['McatId']}'" ;
$rs = mysql_query($sql) or mysql_die();
-
May 23, 2004, 05:10 #5
- Join Date
- May 2004
- Location
- Norway, Oslo
- Posts
- 85
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by DJ P@CkMaN
Personally, I prefer this method:
PHP Code:function SQLError($query, $file, $line, $mysql_error) {
echo "<table cellspacing=\"1\"><tr><th colspan=\"4\">SQL Error - Details</th></tr>
<tr><td><strong>SQL Query:</strong></td><td>$query</td></tr>
<tr><td><strong>File:</strong></td><td>$file</td></tr>
<tr><td><strong>Line:</strong></td><td>$line</td></tr>
<tr><td><strong>MySQL said:</strong></td><td>$mysql_error</td></tr>
</table>";
echo "</body>
</html>";
exit;
} // end function
PHP Code:$query = "SELECT count(*) AS `count` FROM `categories`";
$result = mysql_query($query);
if (!$result) {
SQLError($query, __FILE__, __LINE__, mysql_error());
} // end if
-
May 23, 2004, 06:20 #6
- Join Date
- Aug 2002
- Location
- Burpengary, Australia
- Posts
- 4,495
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
Yeah, I just wrote that function for that post. My won DB object has a much more in-depth error handler
Bookmarks