duai4512 2015-03-21 07:51
浏览 12
已采纳

如何使用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.

  • 写回答

4条回答 默认 最新

  • dquoj04882 2015-03-21 08:27
    关注

    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..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图