flash+php+mysql打造简单留言本教程
刚开始做这个留言本的时候,连mysql和php都没接触过。经过痛苦的查找资料和学习,郁闷了一个星期后完成了我的简单留言本
(主要参考了火山的帖子:★FLASH与ASP通信入门教程——做真正属于自己的留言本!)。网上没有比较好的php留言本相关教程,我下载的N多源文件都看得云里雾里,而且好多都将代码写在MC上。又或许可能有好的教程我没搜到,但无论如何,我现在要在这里班门弄斧一番了。
flash+php+mysql简单留言本教程
目的:
用flash+php+mysql制作一个简单的留言本。
配置环境:
最开始肯定是先配置相应的环境了。我下载的是配置环境套件包,傻瓜式的方法,简易安装,比较适合我。下载地址:http://www.php.cn/ (包括:Apache、PHP、MySQL、Zend Optimizer、phpMyAdmin、 eAccelerator )
文件夹介绍如下(Init.cmd安装;PnCp.cmd控制面板。):
Apache文件夹:PHP服务器(类似IIS)。
MySQL-5.0.15b文件夹:MySQl数据库服务器。
data文件夹:存放的是网站数据库。(留言本的数据库存放于此,后台)
bin 文件夹:里面的文件用来操作数据库(DOS方式)php-5.2.6-Win32文件夹:PHP的函数库,用Apache来解释。
ZendOptimizer文件夹:加速PHP的执行。
htdoc(或www):存放网页文件。(留言本的网页文件放于此,前台)
phpMyAdmin文件夹:操作数据库(Windows方式)
注:
1、安装时会提示你输入MySQl数据库密码,这里密码以“sun”为例。(用户名为“root”)
2、浏览器中输入“http://www.php.cn/”后显示配置相关信息,可以输入MySQl密码进行连接测试。
3、网站目录索引默认是关闭的,用控制台将其开启,便于后期对网站(留言板)的测试。
知识准备(思路):
1、先介绍如何用PHP连上数据库(数据库用户名“root”,密码“sun”,有库“myguestbook”)
2、PHP和MySQl通信(SQL语句:INSERT存,SELECT取):
PHP←MySQl:SELECT * FROM myguestbook;
PHP→MySQL:INSERT INTO myguestbook(name,comment) VALUE ("张三","这是留言");
3、SWF和PHP通信(LoadVars类的sendAndLoad方法存,解析XML的方式取):
SWF←PHP:PHP用echo写xml文件,SWF直接解析该文件。(我以前纳闷为什么蓝色的RSS是PHP格式的,学到这里才明白。)
SWF→PHP:swf用“sendAndLoad”(data_lv.uname="张三")发送变量,php用$name=$_POST['uname']接收变量。
注:
1、留言本其实就是这两个小的过程,PHP相当于一个桥梁。强烈建议将2和3都写出一个简单的例子,例子运行成功了,留言本没开始写就已经完成一大半了。
2、sendAndLoad既可以发送变量给php,也可以接收php的变量(类似于swf读取文本)。可以看火山的教程,很详细。
开始制作(做好上面的准备工作,下面的会很好理解):
1、SWF读取数据
①和②MySQl→PHP→SWF
PHP用“SELECT”从MySQl那里取,再写成xml给SWF读。
2、SWF储存数据
③和④SWF→PHP→MySQl
SWF用“sendAndLoad”给PHP,PHP用“INSERT”给MySQl。
点击放大
完成后的截图:
其他注意事项:
解决乱码(解决数据库中的中文读出来是"????"):
在用PhpAdmin建立数据库的时候选择“utf8-geeral-ci”编码。
在php文件的查询语句前,加上:mysql_query("set names 'utf8'");
php模块化(便于以后修改):
连接数据库的语句写在单独的文件中,如connectdb.php。
则写数据(datatosql.php)和读数据(datatoxml.php)的文件中加上:require "connectdb.php"即可。
MySQL排错函数(如操作有错,根据提示会很方便修改):
mysql_errno(出错号);mysql_error(出错原因)。
php的日期函数(更详细的可参考其他帮助):
data("Ymd,l,H:i"); //20080608,Sunday,09:28
SWF实时刷新(保证读取最新数据):
swf发送并获取实时变量:data_lv.sendAndLoad("datatosql.php?n="+random(9999), data_lv, "post");
swf读取实时xml:myXML.load("datatoxml.php?n="+random(9999));

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.
