Jump to content

Recommended Posts

Hi,

 

I am new to php and am trying to develop a back end login system. I am having problems trying to get it to display the users first and last names when they login. I was wondering if anyone could help with this. The MySQL version on my server is 5.0.51a.

 

The database has two tables for the users, fdologins and fdomemberdetails.

 

The fdlogins table looks like this:

| id | username | password | ref | email | location | postcode |

 

The fdomemberdetails table looks like this:

| id | memberid | firstname | surname | address1 | adress2 | adress3 | postcode | telephone |

 

The 'id' in fdlogins is the same as the 'memberid' in fdomemberdetails.

 

When a user login a session is created with the following:

SESS_LOGGEDIN = 1

SESS_USERNAME - takes the username

SESS_USERID - takes the memberid

 

I have tried the following MySQL query to no avail.

 

<?php$username = mysql_query("SELECT fdomemberdetails.firstname, fdomemberdetails.surname FROM fdomemberdetails INNER JOIN fdologins ON fdologins.username = '{$_SESSION['SESS_USERNAME']}', WHERE fdologins.id = fdomemberdetails.memberid ");?>

 

 

 

<?phpwhile ($row= mysql_fetch_array($username)){echo $row["firstname"] ; echo $row["surname"] ; }?>

 

 

I would be very grateful for any help you can provide on this. If you require any additional information please let me know.

 

Thank you for your help.

 

Regards,

Andy

Link to comment
https://forums.phpfreaks.com/topic/214622-php-mysql-query-help/
Share on other sites

Hi

 

You appear to have the WHERE clause and ON clause mixed up (although they might manage to work like that)

 

<?php

$username = mysql_query("

SELECT fdomemberdetails.firstname, fdomemberdetails.surname

FROM fdomemberdetails

INNER JOIN fdologins ON  fdologins.id = fdomemberdetails.memberid

WHERE  fdologins.username = '".$_SESSION['SESS_USERNAME']."'");

?>

 

Give that a try.

 

All the best

 

Keith

Thank you for your reply Keith.

 

I managed to get it to work. Think I was trying to be over complicated with the query.

 

This is what I used to get it to work.

 

$fullname = mysql_query("select fdomemberdetails.firstname, fdomemberdetails.surnamefrom fdomemberdetailswhere fdomemberdetails.memberid = '{$_SESSION['SESS_USERID']}'limit 1");

 

 

Once again thank you for your time.

 

Regards,

Andy

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.