Jump to content

SQL error


Drezard

Recommended Posts

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

[QUOTE]

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

[/QUOTE]

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:
[CODE]
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();
[/CODE]

Heres the classes.php:
(ive lefted out the class web bit and the connect() function)
[CODE]
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);

}
[/CODE]

- Cheers, Daniel

N e solutions please tell me cause i have no clue

Link to comment
Share on other sites

[code] $myclass = new web;
$upload_class->page = "index";
$upload_class->table = "index";


$myclass->display_information();[/code]

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.