Click to See Complete Forum and Search --> : error when trying SELECT FROM WHERE


spliff
04-30-2007, 06:09 AM
Hello. I have a MySQL database with 2 columns (column, and column2 for argument's sake). column values are 1 word, short, and column2 is the content.

When using this PHP script:

<?php

mysql_connect("localhost", "admin", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$id=$_GET['p'];

$result = mysql_query("SELECT * FROM table WHERE column='$id'") or die(mysql_error());

$row = mysql_fetch_array( $result );

echo $row['column2'];

?>

I get the following error (when filling in ?p=report)

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 'table WHERE column='report'' at line 1


I have used this method before without any problems but in that case the values in 'column' were integers, as opposed to single words now.

What am I doing wrong? I appreciate any help.

bathurst_guy
04-30-2007, 06:42 AM
Try SELECT * FROM `table` ...
Is table the name of the table?

spliff
04-30-2007, 06:46 AM
no actually 'index' is the name of the table.

spliff
04-30-2007, 06:51 AM
changing the name of the table helped :/

problem solved

DARTHTAMPON
04-30-2007, 04:39 PM
index is a sql keyword you may want to change the name of that table to prevent future problems.