PHP - pls whats wrong with my popup login script

Asked By Olusegun A. on 24-May-12 01:35 PM

I have a popup login script in which once a visitor clicks on LOGIN link on any page, login form will popup. The script is as below.
<style type="text/css">
#popupbox{
margin: 0;
margin-left: 40%;
margin-right: 40%;
margin-top: 50px;
padding-top: 10px;
width: 20%;
height: 150px;
position: absolute;
background: #FBFBF0;
border: solid #000000 2px;
z-index: 9;
font-family: arial;
visibility: hidden;
}
</style>
<script language="JavaScript" type="text/javascript">
function login(showhide){
if(showhide == "show"){
document.getElementById('popupbox').style.visibility="visible";
}else if(showhide == "hide"){
document.getElementById('popupbox').style.visibility="hidden";
}
}
</script>

<div id="popupbox">
<?php
if(isset($_POST[Submit11])){
$email=stripslashes($_POST[email]);
$pword=stripslashes($_POST[pword]);
$pw=md5($pword);

if($email=="") echo "Enter your Email.<br>";
elseif($pword=="") echo "Enter your Password.<br>";
else { echo "<b>Welcome</b><br>";
echo "<meta http-equiv='refresh', content='2'>";}
}
?>
<form name="login" action="" method="post">
<center>Username:</center>
<center><input name="username" size="14" /></center>
<center>Password:</center>
<center><input name="password" type="password" size="14" /></center>
<center><input type="submit" name="submit" value="login" /></center>
</form>
<br />
<center><a href="javascript&#058;login('hide');">close</a></center>
</div>

<a href="javascript&#058;login('show');">login</a>

My problem here is that once the visitor clicks on "login" button on the pop up window without entering his username or password, the window will just disappear instead of echoing "Enter your Username or password". Also if the member enters his username and password correctly, the window will just disappear instead of echoing welcome and refresh the page on which the member clicked login.

Pls what do I do wrong. Thanks

Goniey N (Mr. G) replied to Olusegun A. on 25-May-12 12:47 AM
i have no much idea about the PHP, but you have to create two pages....one for welcome page & second for error page...


when user will enter invalid username or password then redirect his/her to that error page & give link to try again...

if user will enter correct username & password then redirect his/her to welcome page....



i don;t know how to do this programatically in PHP, but the logic behind is this...



hope this will help you...
Jitendra Faye replied to Somesh Yadav on 25-May-12 01:17 AM
If you want to show modal popup then use jquery popup.


after adding jqueryui plugin you can use it.


like this-


<script>


function funShow() {

$('#dialog).dialog({ resizable: false, height: 140, modal: true });

}
</script>


<div id="dialog" title="Basic dialog">hi
</div>



<asp:Button runat="server" Text="Button" onClientClick="return funShow()" />


FOR EXAMPLE FOLLOW THIS

-http://jqueryui.com/demos/dialog/

Ramendra Kumar replied to Olusegun A. on 25-May-12 01:28 AM
from where you are calling this login function call like this,don't forget to use return ok, after that in your code of javascript where condition doesn't match write there retuen false;
if where condition match write true; it will solve your problume
onclick="return login('ParameterValueWhich you want to pass');

let me know what happens
Olusegun A. replied to Goniey N (Mr. G) on 25-May-12 06:15 AM
Thanks to everyone, i appreciate it greatly. Let me try and implement your suggestions.

Thanks
Jitendra Faye replied to Olusegun A. on 28-May-12 12:35 AM
Sure , Just try and let me know if you have any issues.
[)ia6l0 iii replied to Olusegun A. on 28-May-12 08:57 AM
Lots of unknowns in your code:

a) You seem to talking of a validation that shows a message "Enter your Username or password". But I don't see that piece of code in you what you have posted. 

b) You seem to be talking of a validation message that reads "Enter your Username or password", but the post variables you read are email and password. Are you sure you use email address as username? Please change it accordingly otherwise.

c) The div id'd popupbox should not contain the php code. It can remain outside. 

d) What is the condition "f(isset($_POST[Submit11])){ " doing? I don't understand what the "submit11" stands for. Is this a custom method?

e) Wrap your conditions , like the one below, in a separate flower brace. 
if($email=="") echo "Enter your Email.<br>"; 

should be:
if($email=="")
{
echo "Enter your Email.<br>";
 
}

Hope this helps.