如何使用PHP和MySQLi在我的页面上构建一个真实的实时帖子系统?

I am building a PHP website. The main purpose of the website site is as follows:

  1. PHP to check database and see if a user's birthdate (day and month) is equal to today's date (day and month) and if its equal, PHP should echo example "Today is James Oduro's Birthday". This will be echoed on the main page "go.php"

  2. PHP should check database and show all registered members on the main page "go.php" which includes user's FirstName, LastName and Birthdates and Picture.

  3. User should be able to post a simple congratulation message on the page to other users who are having their Birthdays.

Now, I have done 50% percent of the work which includes "PHP login script and validation", registration script, and validation using PHP, PHP checking database and seeing if a user has birthday and echoing on the main page and Also showing all registered members on the page, logout script and PHP echoing user's Firstname on top of the page using SESSIONS variables.

My website is on a testing server and I would want to give you an account to login see how the page looks like and I would ask questions regarding to it.

account to login is : Email: jamesoduro@yahoo.com, Password: test, Address is: www.bsystem.besaba.com

I assume you've login already so my question follows:

  1. How should I implement PHP code that when user's write something and click on post then it will be stored in database and later show it on the page under the post form?

  2. How can I also let users upload their simple avator or photo and show it behind their name and details on the Registered members?

Please note that I will provide all my codes and files upon request.

ok first create a table in database and name it user_post like below

CREATE TABLE IF NOT EXISTS `user_post` (
`id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `user_post` text NOT NULL,
  `post_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `post_status` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `user_post`
 ADD PRIMARY KEY (`id`);

 ALTER TABLE `user_post`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

using your post form insert post on submit button click like below

$sql=mysql_query("insert into `user_post`(`user_id`,`user_post`,`post_time`,`post_status`) values('".$_SESSION['user_id']."','".$_POST['post']."',now(),1)");

Fetch code like below

$sql=mysql_query("select * from `user_post` where user_id='".$_SESSION['user_id']."' order by id DESC");
while($result=mysql_fetch_array($sql))
{?>
    Your Html Code
<?php }?>

remember session value i have taken is just an example you have to take your session value in place of mine

hope this will help you..

you can just simply insert post into database table using the user's session value like username or whatever you want to store with the post and time of post with a status(active/deactive).. and after every insertion you can fetch all the records from table using session's value that you stored in table.. you can fetch using php or can use ajax for showing post on runtime

You can get person which is birthday today, using following query. but Instead of static date you need to Date('d') it will give current day and Date('m') it will give current month, its a php functions

SELECT * FROM tbl_birth WHERE DAY(birdthData)=DAY('2015-03-21') AND MONTH(birdthData)=MONTH('2015-03-21')

If you want to insert on the same html page than leave from action like below

<form action="" method="POST">

and before insertion code check a condition submit button's value is set or not like below

if(isset($_POST['your_submit_button_name']))
{
$sql=mysql_query("insert into `user_post`(`user_id`,`user_post`,`post_time`,`post_status`) values('".$_SESSION['user_id']."','".$_POST['post']."',now(),1)");
if($sql)
{?>
<script>
alert("your post has been successfully posted");
window.location.href='your_desired_location.php';
</script>

<?php }}?>