SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Error

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2004
    Location
    Nepal
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post 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!!

  2. #2
    Romans 12:2 codyrockx's Avatar
    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

  3. #3
    SitePoint Enthusiast EspenA's Avatar
    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()); 

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    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(); 

  5. #5
    SitePoint Enthusiast EspenA's Avatar
    Join Date
    May 2004
    Location
    Norway, Oslo
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    It's easier to find errors if you lay your code out properly and make up some nice SQL error handler function
    Nice function 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 
    And then:

    PHP Code:
    $query "SELECT count(*) AS `count` FROM `categories`";
    $result mysql_query($query);

    if (!
    $result) {
      
    SQLError($query__FILE____LINE__mysql_error());
    // end if 

  6. #6
    ********* Wizard silver trophy Cam's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •