I'm creating a website where you can post things and write what's going on, and you have a wall-like thing for you. You can post things. On your wall are all the things people have posted (for now it's just the things you have posted). I am able to make it echo the things that you have posted, but not who it's posted by. EG: If I post "hi everyone" I want it to show who posted it. I tried changing my code, but had no luck, so reverted it back. By the way, I'm twelve, so some of my coding won't be perfect :D Here's the code.
Template.php (place where users can post things)
<?php include("header.php"); ?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title>Simul</title>
</head>
<body style="overflow-y:hidden; overflow-x:scroll">
<hr id="divider">
<br>
<br><br>
<form action='write.php' method='POST' style="position: fixed" name="content">
<h2 style="position:fixed">What's Going On?<br><br><textarea rows="8" cols="30" style="resize:none" name="content"></textarea>
<input type="submit" id="cb3" value="Post" name="post">
</form>
<?php
$channel_check = mysql_query("SELECT content FROM wgo WHERE Posted_By='$user' ORDER by `date` DESC;");
$numrows_cc = mysql_num_rows($channel_check);
if ($numrows_cc == 0) {
echo ''; // They don't have any channels so they need to create one
?>
<h4>                                                                                                             You haven't posted anything yet. You can post what's going on in your life, how you're feeling, or anything else that matters to you.</h64>
<?php
}
else
{
?>
<div id="recentc">
<?php
echo"<h2 id='lp'> Latest Posts</h2>";
while($row = mysql_fetch_assoc($channel_check)) {
$channel_name = $row['content'];
?>
<div>
<?php echo "<b><h6 id='lp2'> $channel_name</h6></b><p />";
}
}
?>
</div>
</body>
</html>
write.php
<?php include 'header.php'?>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<?php if (@$_POST['post']) {
$Posted_By = $user;
$content = $_POST['content'];
$date = date("Y-m-d");
if ($content == '') {
echo "Write What is Going On";
}
else {
$create_a_post = mysql_query("INSERT INTO wgo VALUES ('','$date','$Posted_By','$content')");
header ("Location:template.php");
}
}``
?>
First of all you need to post username in hidden form field for doing this .Then only you can get username of the person who have posted it.
Use the following in between form tag
<input type="hidden" id="user" name="user" value="<?php $username; ?>">
Your problem is with $user
is it? I see the variable $user
is used the first time on the line
$channel_check = mysql_query("SELECT content FROM wgo WHERE Posted_By='$user' ORDER by `date` DESC;");
without it actually being declared at first. So your code cannot retrieve $user
from the database since it is undefined. Also, it cannot insert anything into the database because it is undefined. Find out the user's name (maybe through the use of session), assign it to $user and then you can post and retrieve its value.