PDA

View Full Version : What I'm I doing wrong -Login



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);

liggett78
28 May 2007, 11:12 AM
Could you please use [CODE] or [PHP] tags (the 3 last buttons in the editor) to format you code, just for readability purposes.

I just quickly tested your code and both Firebug and ieHTTPHeaders with IE report all post parameters (user, pass & module) correctly.

sphinix
28 May 2007, 11:25 PM
true firebug parses thru the code without errors but the user,and pass parameters are not sent to the function login.thus authentication and loading of the index.php page fails.

THANKS for telling me about CODE tags.I was wondering how to do that

liggett78
28 May 2007, 11:41 PM
Here is what I get with IE7. Notice POST request to test.php and parameters in the body of the request.

sphinix
2 Jun 2007, 6:25 AM
Here is what I get with IE7. Notice POST request to test.php and parameters in the body of the request.

i don't really know what that really means but this is the response from firebug
"Loading..."
and that is all.it does not redirect me to the next page.plus when i try putting echo to trace where the code fails,i realise the username and password are not passed to the function login()

IE just says Error: Server 1

jsakalos
2 Jun 2007, 4:04 PM
Hi sphinix,

I don't have answer to your question, I have one link that might be of interest for you instead. Here it is: Log in form (http://extjs.com/forum/showthread.php?t=6776)