Home  >  Article  >  Backend Development  >  How to implement storage with ExtJS, PHP and MySQL_PHP Tutorial

How to implement storage with ExtJS, PHP and MySQL_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:38:561142browse

1 Create database and registration table

Copy code The code is as follows:

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 Create register.php and save.php
register.php Call ExtJS file
save.php data storage
register.php=>
Copy code The code is as follows:



Register








save.php=>
Copy code The code is as follows:

if ($_POST['password']!=$_POST['repassword'])
{
//Do not perform storage
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 "Registration successful";
}
else
{
echo "Registration failed";
}
mysql_close($conn);
?>

3 ExtJs file register.js written
register.js=>
Copy code The code is as follows:

Ext.onReady(function() {
function registerhandler(){
var values ​​= Ext.getCmp("form").getForm( ).getValues(); //Get textfield, radio and other values ​​in the form
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: 'Login account:'
},{
x: 80,
y: 0,
name:'login',
anchor:'100%'
},{
x: 0,
y: 30,
xtype:'label',
text: 'User name:'
},{
x: 80 ,
y: 30,
name:'name',
anchor: '100%',
},{
x:0,
y:60,
xtype:'label',
text:'ID number:'
},{
x:80,
y:60,
name:'id',
anchor :'100%',
},{
x:0,
y:90,
xtype:'label',
text:'User password:'
}, {
x:80,
y:90,
inputType:'password',
name:'password',
anchor:'100%',
},{
x:0,
y:120,
xtype:'label',
text:'Password confirmation:',
},{
x:80,
y :120,
name:'repassword',
inputType:'password',
anchor:'100%',
},{
x:80,
y:150 ,
xtype:'radio',
name:'sex',
fieldLabel:'gender',
boxLabel:'male',
inputValue:'b' //radio selection The values ​​are: b
},{
x:0,
y:152,
xtype:'label',
text:'Gender:'
},{
x:140,
y:150,
xtype:'radio',
name:'sex',
fieldLabel:'gender',
boxLabel:'female',
inputValue:'g' //The value of radio is: g
},{
x:0,
y:180,
xtype:'label',
text:' User address'
},{
x:80,
y:180,
name:'address',
anchor:'100%'
}]
} );
var window = new Ext.Window({
title: 'Register Account',
width: 400,
height:300,
minWidth:400,
minHeight: 300,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
buttonAlign:'center',
items: form,
buttons : [{
text: 'Register',
handler:registerhandler
},{
text: 'Cancel'
}]
});
window.show( );
});

4 Run http://localhost/register/register.php

5 Enter relevant information and click ‘Register’


6 Post aspect


7 Database aspects


8 Summary

Ext.Window
buttons handler
radio value inputValue

Copy code The code is as follows:

Ext.Ajax.request({
url:
success:
method:
failure:
params:

});

Ext.getCmp().getForm().getValues();
Platform: ExtJS+PHP Eclipse+Apache+MySQLadmin+ firebug

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321634.htmlTechArticle1 Create database and registry copy code as follows: create database db_register; create table db_register.tb_register( reg_loginid varchar( 20) primary key, reg_name varchar(20...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn