Reputation: 15
I'm trying to keep datas for every sessions. You'll understand when you see the code and screenshots.
<?php
require('connect.php');
session_start();
if(isset($_SESSION['email'])) {
echo "Your session is running " . $_SESSION['email'];
echo "</br></br>";
}
$a=$_SESSION['email'];
$sql = "SELECT title, content FROM post";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "Posted by: $a </br> Title: " . $row["title"]. " </br> Content: " . $row["content"]. "</br></br>";
}
} else {
echo "0 results";
}
?>
<html>
<head></head>
<body>
<form action="post.php" method="post">
You can add new content or <a href='logout.php'>Logout</a></br></br>
Your Email:</br>
<input type="text" required autocomplete="off" name="email"/></br></br>
Title:</br>
<input type="text" required autocomplete="off" name="title"/></br></br>
Content:</br>
<textarea rows="4" cols="50" required autocomplete="off" name="content">
</textarea></br></br>
<input type="submit" value="Send">
</form>
</body></html>
When I'm logging in with [email protected]. It looks like that; First
but when i'm logging in with a@a. It looks like that; Second
I want to keep every content for each sessions. When i enter something with [email protected] and after logging out from this session. I want to see "Posted by : [email protected]" (I mean, with email which written that content) with other sessions too. I do not see my current session mail everytime. How can i do that ?
Upvotes: 0
Views: 34
Reputation: 41
In your post.php
you should save the emailaddress also in your posts
table.
Your query wil be something like this: "SELECT title, content, email FROM post"
.
The output will be: echo "Posted by: " . $row["email"] . "</br> Title: " . $row["title"]. " </br> Content: " . $row["content"]. "</br></br>"
;
Upvotes: 1