ExtJS与PHP、MySQL实现存储的方法
2015-01-24信息快讯网
ExtJS与PHP、MySQL实现存储的方法,需要的朋友可以参考下,里面有详细的步骤。
1 建立数据库、注册表create database db_register; create table db_register.tb_register( reg_loginid varchar(20) primary key, reg_name varchar(20) not null, reg_id int not null, reg_password varchar(20) not null, reg_sex varchar(2), reg_address varchar(50) );
2 建立register.php和save.php
register.php调用ExtJS文件
save.php数据存储
register.php=>
<html> <head> <title>注册</title> <link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" /> <script type="text/javascript" src="../ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="../ext/ext-all.js"></script> <script type="text/javascript" src="register.js"></script> </head> <body> </body> </html>
save.php=>
<?php
if($_POST['password']!=$_POST['repassword'])
{
//不执行存储
exit;
}
$conn=mysql_connect("localhost","root","123");
mysql_select_db("db_register");
$sql="insert into tb_register(reg_loginid,reg_name,reg_id,reg_password,reg_sex,reg_address)
values('".$_POST['login']."','".$_POST['name']."','".$_POST['id']."','".$_POST['password']."','"
.$_POST['sex']."','".$_POST['address']."')";
if(mysql_query($sql,$conn))
{
echo "注册成功";
}
else
{
echo "注册失败";
}
mysql_close($conn);
?>
3 ExtJs文件register.js编写
register.js=>
Ext.onReady(function() {
function registerhandler(){
var values = Ext.getCmp("form").getForm().getValues(); //获取form里textfield、radio等值
Ext.Ajax.request({
url: 'save.php',
success: function() {Ext.Msg.alert("success");},
method: "post",
failure: function(){Ext.Msg.alert("failure");},
params: values
});
}
var form = new Ext.form.FormPanel({
id: 'form',
baseCls: 'x-plain',
layout:'absolute',
url:'save-form.php',
defaultType: 'textfield',
items: [{
x: 0,
y: 0,
xtype:'label',
text: '登录帐户:'
},{
x: 80,
y: 0,
name:'login',
anchor:'100%'
},{
x: 0,
y: 30,
xtype:'label',
text: '用户姓名:'
},{
x: 80,
y: 30,
name:'name',
anchor: '100%',
},{
x:0,
y:60,
xtype:'label',
text:'身份证号:'
},{
x:80,
y:60,
name:'id',
anchor:'100%',
},{
x:0,
y:90,
xtype:'label',
text:'用户密码:'
},{
x:80,
y:90,
inputType:'password',
name:'password',
anchor:'100%',
},{
x:0,
y:120,
xtype:'label',
text:'密码确认:',
},{
x:80,
y:120,
name:'repassword',
inputType:'password',
anchor:'100%',
},{
x:80,
y:150,
xtype:'radio',
name:'sex',
fieldLabel:'性别',
boxLabel:'男',
inputValue:'b' //radio的取值为:b
},{
x:0,
y:152,
xtype:'label',
text:'性别:'
},{
x:140,
y:150,
xtype:'radio',
name:'sex',
fieldLabel:'性别',
boxLabel:'女',
inputValue:'g' //radio的取值为:g
},{
x:0,
y:180,
xtype:'label',
text:'用户住址'
},{
x:80,
y:180,
name:'address',
anchor:'100%'
}]
});
var window = new Ext.Window({
title: '注册帐户',
width: 400,
height:300,
minWidth:400,
minHeight: 300,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
buttonAlign:'center',
items: form,
buttons: [{
text: '注册',
handler:registerhandler
},{
text: '取消'
}]
});
window.show();
});
4 运行http://localhost/register/register.php
5 输入相关信息,点击‘注册'
6 Post方面
7 数据库方面
8 总结
Ext.Window
buttons的handler
radio的取值inputValue
Ext.Ajax.request({
url:
success:
method:
failure:
params:
});
Ext.getCmp().getForm().getValues();
平台:ExtJS+PHP Eclipse+Apache+MySQLadmin+firebug
ThinkPHP与PHPExcel冲突解决方法
让Nginx支持ThinkPHP的URL重写和PATHINFO的方法分享
php Smarty初体验二 获取配置信息
php中Smarty模板初体验
PHP 防注入函数(格式化数据)
PHP源码之explode使用说明
PHP的explode和implode的使用说明
PHP Undefined index报错的修复方法
php max_execution_time执行时间问题
PHP中使用gettext来支持多语言的方法
对text数据类型不支持代码页转换 从: 1252 到: 936
PHP stream_context_create()作用和用法分析
php中突破基于HTTP_REFERER的防盗链措施(stream_context_create)
Wordpress 相册插件 NextGEN-Gallery 添加目录将中文转为拼音的解决办法
使用PHPMYADMIN操作mysql数据库添加新用户和数据库的方法
php截取utf-8中文字符串乱码的解决方法
php上的memcache和memcached两个pecl库
php 字符串函数收集
PHP初学者最感迷茫的问题小结
php echo()和print()、require()和include()函数区别说明
mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数
PHP 最大运行时间 max_execution_time修改方法
php下使用SimpleXML 处理XML 文件
两个开源的Php输出Excel文件类
Linux下将excel数据导入到mssql数据库中的方法
php 操作excel文件的方法小结
PHP 抓取新浪读书频道的小说并生成txt电子书的代码
PHP 读取文件内容代码(txt,js等)
PHP源码之 ext/mysql扩展部分
连接到txt文本的超链接,不直接打开而是点击后下载的处理方法
PHP中查询SQL Server或Sybase时TEXT字段被截断的解决方法