Jump to content


Photo

SQL error


  • Please log in to reply
2 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 19 October 2006 - 11:20 AM

Hello, I have connected to the database and everthing like that its just i get this error:


Error in query: SELECT FROM . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM' at line 1


Hes the code, I have 2 files ones called classes.php and the other is index.php. Now classes.php contains the necessary functions to connect to the mysql, it connects but it just gives me that error. I want index.php to display the info in the database under the table index and field index through the homemade function in classes.php called

Heres the two bits ull need to help

index.php:
include('classes.php');									
	// classes.php contains all the classes
		$myclass = new web;
		$upload_class->page = "index";
		$upload_class->table = "index";
		
	$myclass->connect();	
	
	$myclass->display_information();

Heres the classes.php:
(ive lefted out the class web bit and the connect() function)
function display_information() {
		
$page = trim($this -> page);
$table = trim($this -> table);
				
		$query = "SELECT $page FROM $table";

		$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

		if (mysql_num_rows($result) > 0) {

    		echo "<table cellpadding=10 border=1>";
    		
			while($row = mysql_fetch_row($result)) {
        		
				echo "<tr>";
        		echo "<td>".$row[0]."</td>";
        		echo "</tr>";
				
    		}
			
    		echo "</table>";
			
		}
		
		else {

    		echo "No rows found!";
		}

	mysql_free_result($result);

	mysql_close($connection); 	
	
	}

- Cheers, Daniel

N e solutions please tell me cause i have no clue



#2 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 19 October 2006 - 12:04 PM

help me please.

#3 pnj

pnj
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 19 October 2006 - 12:07 PM

$myclass = new web;
		$upload_class->page = "index";
		$upload_class->table = "index";
		
	
	$myclass->display_information();

The error suggests $this->page and $this->table are not set in the class function.

In your code, you have initialized the fields page and table in the $upload_class variable, but then called display_information() with the $myclass variable, so page and table are empty.

Cheers,
pnj




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users