Login and user profile
This commit is contained in:
parent
e54e877a7a
commit
5c39988fc7
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_unset();
|
||||||
|
session_destroy();
|
||||||
|
header("Location: /"); die();
|
||||||
|
?>
|
64
user.php
64
user.php
|
@ -1,9 +1,65 @@
|
||||||
<?php
|
<?php
|
||||||
$db = new SQLite3('ask.db');
|
$db = new SQLite3('ask.db');
|
||||||
|
|
||||||
$version = $db->query("SELECT * FROM users;")->fetchArray(SQLITE3_ASSOC);
|
$user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
|
||||||
|
|
||||||
var_dump($version);
|
$db->exec("CREATE TABLE IF NOT EXISTS questions(
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
user INTEGER,
|
||||||
|
by INTEGER,
|
||||||
|
question TEXT
|
||||||
|
);");
|
||||||
|
|
||||||
echo "\n";
|
//if(!$db->querySingle("SELECT * FROM users where id = 0;")){
|
||||||
?>ñ
|
// echo "ta;yf";
|
||||||
|
// $db->exec()
|
||||||
|
//}
|
||||||
|
//else{
|
||||||
|
// echo "tft;y";
|
||||||
|
//}
|
||||||
|
|
||||||
|
if($validUser){
|
||||||
|
header("Location: /"); die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$errorMsg = "";
|
||||||
|
if(isset($_POST["post-submit"])){
|
||||||
|
if($_POST["post-text"] == "") $errorMsg = "The question can't be blank.";
|
||||||
|
else if(strlen($_POST["post-text"]) > 400) $errorMsg = "The question can't bee longer than 400 characters";
|
||||||
|
else{
|
||||||
|
$u = $user["id"];
|
||||||
|
$by = 0;
|
||||||
|
$question = htmlspecialchars($_POST["post-text"]);
|
||||||
|
|
||||||
|
// Insert user into DB
|
||||||
|
$db->exec("INSERT INTO questions(user,by,question) VALUES ('$u','$by','$question');");
|
||||||
|
unset($_POST["post-text"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><?= $user["username"] ?> | LibreCat</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2><?= $user["username"] ?></h2>
|
||||||
|
<p><?= $user["bio"] ?></p>
|
||||||
|
|
||||||
|
<form name="input" action="" method="post">
|
||||||
|
<p>Ask me anything</p>
|
||||||
|
<textarea id="post-text" name="post-text"></textarea>
|
||||||
|
<br/>
|
||||||
|
<?php if(isset($errorMsg)) echo "<p>$errorMsg</p>\n"; ?>
|
||||||
|
<input type="submit" name="post-submit"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $user["id"] . "' LIMIT 0, 10;");
|
||||||
|
while($current = $qs->fetchArray(SQLITE3_ASSOC)){
|
||||||
|
echo("<h3>". $current["by"] ."</h3>");
|
||||||
|
echo("<p>". $current["question"] ."<p>");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue