PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
adsegzy
Forum Contributor
Posts: 184 Joined: Tue Jul 28, 2009 9:26 am
Post
by adsegzy » Thu May 24, 2012 12:19 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.
login.php
Code: Select all
<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:login('hide');">close</a></center>
</div>
<a href="javascript: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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu May 24, 2012 12:37 pm
Your form has fields 'username' and 'password' but you're checking for 'email' and 'pword'.
The PHP bit only runs if $_POST['Submit11'], which doesn't exist, is set (ie. it never runs).
You're never actually checking if what they've entered is valid or not.
adsegzy
Forum Contributor
Posts: 184 Joined: Tue Jul 28, 2009 9:26 am
Post
by adsegzy » Thu May 24, 2012 4:33 pm
Ok Celauran, I have rewrite the form now
if(isset($_POST[submit11])){
$email=stripslashes($_POST[email]);
$pword=stripslashes($_POST[pword]);
$pw=md5($pword);
if($email=="") echo "<span class='red'>Enter your Email.</span><br>";
elseif($pword=="") echo "<span class='red'>Enter your Password.</span><br>";
else echo "<span class='green'><b>Welcome</b></span><br>";
}
?>
<form name="login" action="" method="post">
<center>Email:</center>
<center><input name="email" size="14" /></center>
<center>Password:</center>
<center><input name="pword" type="password" size="14" /></center>
<center><input type="submit" name="submit11" value="login" /></center>
</form>
but still doing the same thing (disappearing). what else?