No tak jedna dobra wiadomosc ktora dobrze nakieruje i juz ma to jakis sens

w pliku Twoj profil mam taki kod:
<?php
$title = "Twoje konto";
include_once 'header.php';
if (!$session->is_logged_in()) {
$session->message("Musisz sie zalogowac!", "success");
redirect_to("login.php");
}
?>
<h1>Twoje konto</h1>
<?php
if (isset($_POST['submit'])) { $newpassword = sanitize($_POST['newpassword']);
$newemail = sanitize($_POST['newemail']);
$oldpassword = sanitize($_POST['oldpassword']);
$userdata = User::getUser($session->user_name);
$validate = new Validation();
$validate->addSource($_POST);
$validate->addRule('newpassword', 'string', false, '4', '20', true);
$validate->addRule('newemail', 'email', false, '3', '30', true);
$validate->addRule('oldpassword', 'string', true, '4', '20', true);
$validate->run();
$email_result = User::exists("email",$newemail);
if($email_result) {
$session->message("Inny uzytkownik zarejestrowany jest juz na tego e-maila!", "warning");
redirect_to("account.php");
}
}
if (!empty($oldpassword)) { if (secure_string($oldpassword) !== $userdata->password) {
$session->message("Niepoprawne stare haslo!", "warning");
redirect_to("account.php");
}
}
if (sizeof($validate->errors) > 0
) { echo("<div id='normal'><div class='warning'>"); foreach ($validate->errors as $error) { echo "- ".$error."<br/>"; } echo("</div></div><br />");
} else {
$user = new User();
$user->id = $userdata->id;
$user->username = $userdata->username;
if (!empty($newpassword)) { $user->password = secure_string($newpassword);
} else {
$user->password = $userdata->password;
}
$user->email = $newemail;
} else {
$user->email = $userdata->email;
}
$user->status = $userdata->status;
$user->actcode = $userdata->actcode;
$user->created_at = $userdata->created_at;
$result = $user->update();
if ($result) {
$session->message("Zmiany zapisane!", "success");
redirect_to("account.php");
} else {
$session->message("Blad, nie zapisano zmian!", "warning");
redirect_to("account.php");
}
}
}
if (isset($_POST['delete'])) {
$userdata = User::getUser($session->user_name);
$oldpassword = sanitize($_POST['oldpassword']);
$validate = new Validation();
$validate->addSource($_POST);
$validate->addRule('oldpassword', 'string', true, '4', '20', true);
$validate->run();
if (!empty($oldpassword)) { if (secure_string($oldpassword) !== $userdata->password) {
$session->message("Niepoprawne stare haslo!", "warning");
redirect_to("account.php");
}
}
if (sizeof($validate->errors) > 0
) { echo("<div id='normal'><div class='warning'>"); foreach ($validate->errors as $error) { echo "- ".$error."<br/>"; } echo("</div></div><br />");
} else {
$user = new User();
$user->id = $userdata->id;
$result = $user->delete();
if($result) {
$session->logout();
$session->message("Twoje konto zostalo usuniete!!", "success");
redirect_to("index.php");
}
}
}
?>
<form method="post" name="submit" id="submit" action="account.php">
<table>
<tr>
<td>Nick: </td>
<td><input name="username" id="username" readonly="readonly" type="text" maxlength="15" size="15" value="
<?php echo $session->user_name; ?>"/></td>
</tr>
<tr>
<td>Nowe hasło: </td>
<td><input name="newpassword" id="newpassword" type="password" maxlength="30" size="15" value="<?php
if(isset($_POST['newpassword'])) { echo $_POST['newpassword']; }
?>"/></td>
</tr>
<tr>
<td>Nowy E-mail : </td>
<td><input name="newemail" id="newemail" type="text" maxlength="30" size="15" value="<?php
if(isset($_POST['newemail'])) { }
?>"/></td>
</tr>
<tr>
<td>Stare haslo: </td>
<td><input name="oldpassword" id="oldpassword" type="password" maxlength="30" size="15" value="<?php
if(isset($_POST['oldpassword'])) { echo $_POST['oldpassword']; }
?>"/></td>
</tr>
</table>
<input class="button" type="submit" name="delete" id="delete" value="Usun konto!"/>
<input class="button" type="submit" name="submit" id="submit" value="Zapisz!"/>
</form>
<?php
include_once 'footer.php';
?>
Pobralem jakis silnik strony z chomikuj sam poczatek bez stylow niczego tylko rejestracja logowanie i wyswietlanie profilu i z tego co tutaj wychodzi to logowanie opiera sie na sesji skoro jest $session dobrze mysle

? I teraz zeby zrobic to na podstawie loginu czy id tak jak napisal kolega moderator musialbym to napisac tak:?
SELECT id FROM users WHERE money?

Probowalem ale nic nie pomoglo