Merge branch 'marijn-settings' into 'master'

Settings work with sql, session is hardcoded to 2 glob db

See merge request !53
This commit was merged in pull request #57.
This commit is contained in:
Marijn Jansen
2017-01-17 16:50:19 +01:00
6 changed files with 125 additions and 29 deletions

View File

@@ -5,7 +5,7 @@ if ($dbconf === FALSE) {
die("Error parsing XML file");
}
else {
$db = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
$GLOBALS["db"] = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
"$dbconf->mysql_username", "$dbconf->mysql_password")
or die('Error connecting to mysql server');
}

View File

@@ -0,0 +1,46 @@
<?php
function getSettings() {
$stmt = $GLOBALS["db"]->prepare("
SELECT
`fname`,
`lname`,
`email`,
`location`,
`birthdate`,
`bio`,
`profilepicture`
FROM
`user`
WHERE
`userID` = :userID
");
$stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute();
return $stmt->fetch();
}
function updateSettings() {
$stmt = $GLOBALS["db"]->prepare("
UPDATE
`user`
SET
`fname` = :fname,
`lname` = :lname,
`location` = :location,
`birthdate` = :bday,
`bio` = :bio
WHERE
`userID` = :userID
");
$stmt->bindParam(":fname", $_POST["fname"]);
$stmt->bindParam(":lname", $_POST["lname"]);
$stmt->bindParam(":location", $_POST["location"]);
$stmt->bindParam(":bday", $_POST["bday"]);
$stmt->bindParam(":bio", $_POST["bio"]);
$stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute();
}