Please Help!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Please Help!

Post by apple »

This is my code:

Code: Select all

<?php
$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c  WHERE c.names_id = n.{$_SESSION['id']}";
?>
This is the error

Code: Select all

Unknown column 'n.2' in 'where clause'
What is the right code?
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Please Help

Post by apple »

Please Help Me!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what are you trying to "paste" in there? what's the structure of table "name"
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

This is the Structure

Post by apple »

Database: HRM

Table: names
id
first_name
last_name
email
registration_date


Table: company
id
names_id
company_name
address
phone1
phone2
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

I was trying to get the SESSION data

Post by apple »

Thanks a lot
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what do you mean by the session data?
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

I think somewhere is wrong on this code

Post by apple »

Code: Select all

n.&#123;$_SESSION&#1111;'id']&#125;";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that isn't a field in your names table.

try

Code: Select all

$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c  WHERE c.names_id = '{$_SESSION['id']}'";
[edit:forget that]

try this instead.

Code: Select all

$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c  WHERE c.names_id = n.id";
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

I try your code

Post by apple »

:D I really appreciate your help. Thank you so much.

I try your code. This is the ERROR...
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 'c.name_id = '2'' at line 1
Do you have any other options?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I edited my previous post..

I'm assuming here that company.name_id is supposed to match name.id, yes?
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

Post by apple »

SESSION came from the names (table)

n.id = c. names_id
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

What exactly do you want your Query to return? In your very first post you are trying to select the Names data based on a given ID (stored in a session variable) - is this correct?
Post Reply