PHP:在指定的时间内回显消息

编程入门 行业动态 更新时间:2024-10-23 05:53:08
本文介绍了PHP:在指定的时间内回显消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想显示一个字符串您的状态已发布,持续约3秒钟,而不是我希望它消失的时间。

I want to display a string "Your status has been posted" for something around 3 or so seconds than I want it to go away.

截至目前我有一个新闻提要,用户可以在其中发布消息,并在它们发布后回显该文本字符串,直到重新输入URL。有人有什么建议吗?

As of right now I have a news feed where the user can post messages and after they post it echoes that string of text until the url is re-enetered. Does anyone have any suggestions?

if ($_POST['submit']) { $body = $_POST['body']; if ($body) { include ('connect.php'); $date = date("Y-m-d"); $email = $_SESSION['email']; $who = mysql_query("SELECT firstname FROM people WHERE email = $email"); $insert = mysql_query(" INSERT INTO status VALUES('','$email','$body','$date')"); echo ('Your status has been posted <p></p>'); } else echo 'Status required to post into news feed! <p></p>'; } ?>

状态:

感谢您的帮助!

Jeff

推荐答案

您需要添加一些JavaScript才能执行此操作。以下是入门的概述:

You need to add some JavaScript to do this. Here is an outline to get you started:

<p id="info-message">Your status has been posted</p> <script> setTimeout(function(){ document.getElementById('info-message').style.display = 'none'; /* or var item = document.getElementById('info-message') item.parentNode.removeChild(item); */ }, 3000); </script>

另外,您可能希望淡出效果。为此,我建议使用jQuery或Scriptaculous之类的库。

Also you may want fade-out effects. For that I'd recommend using a library like jQuery or Scriptaculous.

有用的链接: developer.mozilla/zh-CN/Window.setTimeout api.jquery/fadeOut/ script.aculo.us/

哦,顺便说一下,您的脚本容易受到 SQL注入的影响。 >始终转义您的查询参数(或使用准备好的查询)!

Oh, by the way, your script is vulnerable to SQL injection. Always escape your query parameters (or use prepared queries)!

更多推荐

PHP:在指定的时间内回显消息

本文发布于:2023-11-27 07:17:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637102.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   消息   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!