sphinix
28 May 2007, 4:44 AM
I'm trying to do a login dialog using PHP/Mysql and a sample someone posted.
Firebug detects no error but the login function does not seem to recieve variables from the main page:(( :((
here are the codes
test.php
<?php $hostname_conn = "127.0.0.1";
$database_conn = "victory";
$username_conn = "kuji";
$password_conn = "kuji";
$MM_fldUserAuthorization = "staffId";
$MM_redirectLoginSuccess = "../index.php";
$MM_redirectLoginFailed = "/failed.php";
$MM_redirecttoReferrer = true;
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
function Login($user, $pass){
mysql_select_db($database_conn, $conn)or trigger_error(mysql_error(),E_USER_ERROR);
$LoginRS__query="SELECT Username, Password, staffId FROM `user_table` WHERE Username='%user' AND Password='%pass'";
echo $LoginRS__query;
$LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser>0) {
header("Location: " . $MM_redirectLoginSuccess );
} }?>
main.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../ajax/ext/resources/css/ext-all.css" />
</head>
<body>
<script type="text/javascript" src="../ajax/ext/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="../ajax/ext/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="../ajax/ext/ext-all.js"></script>
<script type='text/javascript'>
Ext.SSL_SECURE_URL="ext/resources/images/default/s.gif";
Ext.BLANK_IMAGE_URL="ext/resources/images/default/s.gif";
</script>
<script type="text/javascript" src="ext/ext-all.js"></script>
<!--script type="text/javascript" src="ext/ext-all-debug.js"></script-->
<script type="text/javascript">
Ext.BasicForm.prototype.afterAction=function(action, success){
this.activeAction = null;
var o = action.options;
if(o.waitMsg){
Ext.MessageBox.updateProgress(1);
Ext.MessageBox.hide();
}
if(success){
if(o.reset){
this.reset();
}
Ext.callback(o.success, o.scope, [this, action]);
this.fireEvent('actioncompleted', this, action);
}else{
Ext.callback(o.failure, o.scope, [this, action]);
this.fireEvent('actionfailed', this, action);
}
}
</script>
<script type="text/javascript" src="test.js"></script>
<div id='loginDialogId'></div>
</body>
</html>
test.js
Test = function(){
var dialog, form;
return{
Init:function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
dialog = new Ext.BasicDialog('loginDialogId', {
autoCreate: true,
width: 260,
height: 130,
modal: true,
closable:false,
resizable:false,
draggable:false,
collapsible:false,
title:'Login'
});
dialog.body.dom.innerHTML="<div id='loginFormId'></div>";
form = new Ext.Form({
labelAlign: 'right',
labelWidth: 75,
buttonAlign: 'right',
url:'test.php',
baseParams:{module:'login'}
});
form.add(
new Ext.form.TextField({
fieldLabel: 'Username',
name: 'user'//,
//vtype: 'username',
//allowBlank:false
}),
new Ext.form.TextField({
fieldLabel: 'Password',
name: 'pass',
//vtype: 'password',
defaultAutoCreate : {tag: "input", type: "password", size: "20", autocomplete: "off"}//,
//allowBlank:false
})
);
form.addButton('Login', function(){
form.submit({
waitMsg:'Please Wait...',
reset:true,
success:Test.Success,
scope:Test
});
}, form);
form.render('loginFormId');
dialog.on('show', function(){form.items.item(0).focus();});
dialog.show(document.body.getElementsByTagName('div')[0]);
},
Success: function(f,a){
if(a && a.result && typeof a.result.level == "number"){
Test.level=a.result.level;
alert("level = "+Test.level);
dialog.destroy(true);
}
}
}
}();
Ext.onReady(Test.Init, Test, true);
Firebug detects no error but the login function does not seem to recieve variables from the main page:(( :((
here are the codes
test.php
<?php $hostname_conn = "127.0.0.1";
$database_conn = "victory";
$username_conn = "kuji";
$password_conn = "kuji";
$MM_fldUserAuthorization = "staffId";
$MM_redirectLoginSuccess = "../index.php";
$MM_redirectLoginFailed = "/failed.php";
$MM_redirecttoReferrer = true;
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
function Login($user, $pass){
mysql_select_db($database_conn, $conn)or trigger_error(mysql_error(),E_USER_ERROR);
$LoginRS__query="SELECT Username, Password, staffId FROM `user_table` WHERE Username='%user' AND Password='%pass'";
echo $LoginRS__query;
$LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser>0) {
header("Location: " . $MM_redirectLoginSuccess );
} }?>
main.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../ajax/ext/resources/css/ext-all.css" />
</head>
<body>
<script type="text/javascript" src="../ajax/ext/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="../ajax/ext/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="../ajax/ext/ext-all.js"></script>
<script type='text/javascript'>
Ext.SSL_SECURE_URL="ext/resources/images/default/s.gif";
Ext.BLANK_IMAGE_URL="ext/resources/images/default/s.gif";
</script>
<script type="text/javascript" src="ext/ext-all.js"></script>
<!--script type="text/javascript" src="ext/ext-all-debug.js"></script-->
<script type="text/javascript">
Ext.BasicForm.prototype.afterAction=function(action, success){
this.activeAction = null;
var o = action.options;
if(o.waitMsg){
Ext.MessageBox.updateProgress(1);
Ext.MessageBox.hide();
}
if(success){
if(o.reset){
this.reset();
}
Ext.callback(o.success, o.scope, [this, action]);
this.fireEvent('actioncompleted', this, action);
}else{
Ext.callback(o.failure, o.scope, [this, action]);
this.fireEvent('actionfailed', this, action);
}
}
</script>
<script type="text/javascript" src="test.js"></script>
<div id='loginDialogId'></div>
</body>
</html>
test.js
Test = function(){
var dialog, form;
return{
Init:function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
dialog = new Ext.BasicDialog('loginDialogId', {
autoCreate: true,
width: 260,
height: 130,
modal: true,
closable:false,
resizable:false,
draggable:false,
collapsible:false,
title:'Login'
});
dialog.body.dom.innerHTML="<div id='loginFormId'></div>";
form = new Ext.Form({
labelAlign: 'right',
labelWidth: 75,
buttonAlign: 'right',
url:'test.php',
baseParams:{module:'login'}
});
form.add(
new Ext.form.TextField({
fieldLabel: 'Username',
name: 'user'//,
//vtype: 'username',
//allowBlank:false
}),
new Ext.form.TextField({
fieldLabel: 'Password',
name: 'pass',
//vtype: 'password',
defaultAutoCreate : {tag: "input", type: "password", size: "20", autocomplete: "off"}//,
//allowBlank:false
})
);
form.addButton('Login', function(){
form.submit({
waitMsg:'Please Wait...',
reset:true,
success:Test.Success,
scope:Test
});
}, form);
form.render('loginFormId');
dialog.on('show', function(){form.items.item(0).focus();});
dialog.show(document.body.getElementsByTagName('div')[0]);
},
Success: function(f,a){
if(a && a.result && typeof a.result.level == "number"){
Test.level=a.result.level;
alert("level = "+Test.level);
dialog.destroy(true);
}
}
}
}();
Ext.onReady(Test.Init, Test, true);