/    Sign up×
Community /Pin to ProfileBookmark

error when trying SELECT FROM WHERE

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:

[code=php]<?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’];

?>[/code]

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

[quote]

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

[/quote]

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.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyApr 30.2007 — Try SELECT * FROM table ...

Is table the name of the table?
Copy linkTweet thisAlerts:
@spliffauthorApr 30.2007 — no actually 'index' is the name of the table.
Copy linkTweet thisAlerts:
@spliffauthorApr 30.2007 — changing the name of the table helped :/

problem solved
Copy linkTweet thisAlerts:
@DARTHTAMPONApr 30.2007 — index is a sql keyword you may want to change the name of that table to prevent future problems.
×

Success!

Help @spliff spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...