Results 1 to 4 of 4

Thread: Undefined variable error in Php

  1. #1
    Join Date
    Dec 2008
    Posts
    135

    Undefined variable error in Php

    Hello friends,

    I am getting an error message whenever i am trying to run any query in php.I don't know whats wrong with it.I am getting the following error message as follows


    PHP Notice: Undefined variable: array in C:\xampp\htdocs\mysql_class_2.php

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Undefined variable error in Php

    Sure i will help you out with this is it possible for you to provide me the code so that i can give you a perfect solution for it.

  3. #3
    Join Date
    Dec 2008
    Posts
    135

    Re: Undefined variable error in Php

    Following are the code on which i am getting the error message

    PHP Code:
    <?php
     
    class mysql {
     

      function 
    Connect($host$name$pass$db){
     
      
    $connection mysql_connect("$host","$name","$pass");
      
    mysql_select_db("$db"$connection);
     
      }
    //ends the connection function
     

      
    function Close(){
     
      
    mysql_close($this->connection);
     
      }
    //ends the close function
     

      
    function FetchRow($query){
      
    $rows mysql_fetch_row($query);
      return 
    $rows;
      }
     

      function 
    FetchArray($query){
      
    $array mysql_fetch_array($query);
      return 
    $array;
      }
     
      function 
    FetchNum($query){
       
    $num mysql_num_rows($query);
      return 
    $num;
      }
     

      function 
    Query($sql){
      
    $query mysql_query($sql) or die(mysql_error());
      return 
    $query;
      }
    //ends the query function
     

       
    function FetchAssoc($query2){
       if(
    $query2 and !is_bool($query2)){
      
    $array mysql_fetch_assoc($query2);
             }
      return (
    $array);
             }

     
    /*
      function TanimotoSimilarity($query,$input_arrays) {
                 $i=0;
                 $row= array();
                 while( $row=mysql_fetch_assoc($query) )
            {
     
          $first[$i]=(count(array_intersect($row,$input_arrays)))/(count($row)+count($input_arrays)-count(array_intersect($row,$input_arrays)));
          $i++;
     
            }
     
             return($first);
     
     
    } */

     
    }//ends the class
     
     
    ?>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Undefined variable error in Php

    Try to use the following code instead of your

    PHP Code:
    $x 1;
    $y 2;
    // Because our conditional will return false, it will skip the creation of $xy.
    if ( $x === $y )
    {
      
    $xy $x $y;
    }
    // Therefore, we are now trying to return a variable that doesn't exist.
    return $xy;
     
    $x 1;
    $y 1;
    // Now that the if conditional will return true, it sets the variable and we can
    // successfully return it.
    if ( $x === $y )
    {
      
    $xy $x $y;
    }
    return 
    $xy
    And with that you need to use else statement to return a NULL value for your $array.

Similar Threads

  1. 'DOMParser is undefined' IE7 error message
    By Protectors in forum Technology & Internet
    Replies: 5
    Last Post: 28-01-2012, 08:20 AM
  2. Need for Speed World Undefined Error help
    By Sahira in forum Video Games
    Replies: 6
    Last Post: 20-07-2010, 11:08 AM
  3. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  4. Error: Use of undefined constant in PHP
    By amadeo in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 06:07 PM
  5. Fatal Error : Call to undefined function simplexml_load_file()
    By Ananias in forum Software Development
    Replies: 3
    Last Post: 02-06-2009, 05:43 PM

Tags for this Thread

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
  •  
Page generated in 1,713,619,202.93232 seconds with 17 queries