Jump to content

Sessionname and SQL


derrtyones

Recommended Posts

Hi,

 

I'm quite new to PHP and SQL but still learning it all. Writing and reading to and from a database is something I can do for some weeks but I have been struggling with one problem and it's probaly something easy. I just don't know how to do it. I asked on an other forum before but they weren't very nice to me so I thought I'd try it on this one hope for an answer that works.

 

I got a login script, which might be a little confusing but I'm sure you can figure it out:

<?php
session_start();
?>
      <?php
require ("connection.php");
$gebruikersnaam = $_POST['loginname'];
$wachtwoord2 = $_POST['password'];
$DBNaam = 'mydatabase';
$opdracht = "SELECT * FROM portfolio WHERE password = '$wachtwoord2' AND loginname = '$gebruikersnaam'";
mysql_select_db($DBNaam);
$result = mysql_query($opdracht);
If ($Rij = mysql_fetch_array($result)){
$_SESSION['account'] = '1';
echo "<br> Welcome: ". $Rij['firstname']."";
echo "<br> You are logged in as:<br> ".$Rij['loginname']."";
echo "<br><a href='profile.php'>Click here to view your profile</a>";
}
Else { echo "Your username and/or password do not match!";}
?>

 

Ok so the login works perfectly. It also shows your first name and loginname once your logged in which it reads from the database and it works with different accounts.

 

Now here comes my problem.

As you can read in the script, it will show a link to a page called profile.php. You can't access it if you're not logged in (says NO PERMISSION). You can view the page once your logged in. Ok, so far everything works.

 

Here's what I want:

 

When someone logs in and clicks to go to the profile.php page, it should display only his information.

 

Problem:

- When someone logs in, the sessionname is NOT the same as the logged in user. How do I do that?

- When someone clicks to go to profile.php it displays ALL the users from the table out of the database because at the moment the code is:

 

SELECT * FROM $tabelnaam

 

But it should be something like

 

SELECT * FROM $tabelnaam WHERE ................ here should be the code that it only selects the info of the sessionname.

 

Can someone PLEASE help me? I been struggling for months now and I just don't know how to do this. I looked on many PHP and SQL tutorial sites but it doesn't show my problem. Help!

 

Link to comment
https://forums.phpfreaks.com/topic/124186-sessionname-and-sql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.