Jump to content

[SOLVED] else problem


squiblo

Recommended Posts

Like this:

 

<div id="wb_Shape2" style="position:absolute;left:54px;top:170px;width:793px;height:412px;z-index:10" align="center">
<img src="/Images/body_img.jpg" id="Shape2" align="top" alt="" title="" border="0" width="793" height="412"></div>

<?php
if(isset($_POST['login'])){
$_SESSION['myusername'] = $_POST['myusername'];
$username = $_SESSION['myusername'];
?>
<div id="wb_Text1" style="position:absolute;left:684px;top:55px;width:151px;height:14px;z-index:7" align="right">
<font style="font-size:13px" color="#FFFFFF" face="Arial">You are logged in as:</font><br>
<font style="font-size:15px" color="#FF0000" face="Arial">
<?php
echo ucwords(strtolower($username));
?>
</font></div>
<?php
}
else
{
?>

Link to comment
Share on other sites

this always shows the login form both logged in and not logged in:

<?php
if(isset($_POST['Login'])){
$_SESSION['myusername'] = $_POST['myusername'];
$username = $_SESSION['myusername'];
echo ucwords(strtolower($username));
?>
<div id="wb_Text1" style="position:absolute;left:684px;top:55px;width:151px;height:14px;z-index:7" align="right">
<font style="font-size:13px" color="#FFFFFF" face="Arial">You are logged in as:</font><br>
<font style="font-size:15px" color="#FF0000" face="Arial">
</font></div>
<?php
}
else
{
?>
<form name="form1" method="post" action="checklogin.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
  <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>
   <div id="wb_Text7" style="position:absolute;left:584px;top:66px;width:47px;height:16px;z-index:22" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Username:</font></div>
   <div id="wb_Text8" style="position:absolute;left:586px;top:91px;width:65px;height:16px;z-index:23" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Password:</font></div>
   <div id="wb_Text2" style="position:absolute;left:669px;top:116px;width:111px;height:14px;z-index:7" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Remember Me</font></div>
   <div id="wb_Text3" style="position:absolute;left:651px;top:134px;width:122px;height:14px;z-index:9" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Forgot your password?</font></div>

<?php
}
?>

Link to comment
Share on other sites

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
session_register("myusername");
session_register("mypassword"); 
header("location:profile.php");
}
else {
header("location: http://www.squiblo.com/retrylogin.php");
}
}
?>

Link to comment
Share on other sites

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
session_register("myusername");
session_register("mypassword"); 
header("location:profile.php");
}
else {
header("location: http://www.squiblo.com/retrylogin.php");
}
}
?>

From where this $dbusername is coming?

$_SESSION['myusername']=$dbusername;

 

Why not this and whats the point for storing pass in session.

$_SESSION['myusername'];

 

instead of this:

session_register("myusername");
session_register("mypassword");

 

Now to next script.

 

<?php
if(isset($_POST['Login'])){
?>
echo<div id="wb_Text1" style="position:absolute;left:684px;top:55px;width:151px;height:14px;z-index:7" align="right">
<font style="font-size:13px" color="#FFFFFF" face="Arial">You are logged in as:</font><br>
<font style="font-size:15px" color="#FF0000" face="Arial">
</font></div>

<?php
ucwords(strtolower($_SESSION['myusername']));
}
else
{
?>
<form name="form1" method="post" action="checklogin.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
  <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>
   <div id="wb_Text7" style="position:absolute;left:584px;top:66px;width:47px;height:16px;z-index:22" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Username:</font></div>
   <div id="wb_Text8" style="position:absolute;left:586px;top:91px;width:65px;height:16px;z-index:23" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Password:</font></div>
   <div id="wb_Text2" style="position:absolute;left:669px;top:116px;width:111px;height:14px;z-index:7" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Remember Me</font></div>
   <div id="wb_Text3" style="position:absolute;left:651px;top:134px;width:122px;height:14px;z-index:9" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Forgot your password?</font></div>

<?php
}
?>

Link to comment
Share on other sites

after changing check login to:

$_SESSION['myusername'] = $myusername;

i can login just like normal but on the about.php page the login form is still visable on the page if logged in or logged out, maybe going about it a different way and using include may help, although ive never used include

Link to comment
Share on other sites

checklogin.php:

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
$_SESSION['myusername'] = $myusername; 
header("location:profile.php");
}
else {
header("location: http://www.squiblo.com/retrylogin.php");
}
}
?>

 

about.php:

<?php
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Squiblo - About Us!</title>
<style type="text/css">
div#container
{
   width: 900px;
   position: relative;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
}
body
{
   text-align: center;
   margin: 0;
}
</style>
</head>
<body bgcolor="#E6E6E6" text="#000000">

<div id="container">
<div id="wb_Shape1" style="position:absolute;left:55px;top:41px;width:792px;height:125px;z-index:2" align="center">
<img src="/Images/header_img.jpg" id="Shape1" align="top" alt="" title="" border="0" width="792" height="125"></div>
<div id="wb_Text1" style="position:absolute;left:60px;top:85px;width:325px;height:72px;z-index:3" align="left">
<font style="font-size:70px" color="#FFFFFF" face="impact"><a href="/index.php" style="text-decoration:none"> <font color="#FFFFFF">SQUIBLO</a></font></font></div>


<div id="wb_Shape2" style="position:absolute;left:54px;top:170px;width:793px;height:412px;z-index:10" align="center">
<img src="/Images/body_img.jpg" id="Shape2" align="top" alt="" title="" border="0" width="793" height="412"></div>


<?php
if(isset($_POST['Login'])){
?>
echo<div id="wb_Text1" style="position:absolute;left:684px;top:55px;width:151px;height:14px;z-index:7" align="right">
<font style="font-size:13px" color="#FFFFFF" face="Arial">You are logged in as:</font><br>
<font style="font-size:15px" color="#FF0000" face="Arial">
</font></div>

<?php
ucwords(strtolower($_SESSION['myusername']));
}
else
{
?>
<form name="form1" method="post" action="checklogin.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
  <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>
   <div id="wb_Text7" style="position:absolute;left:584px;top:66px;width:47px;height:16px;z-index:22" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Username:</font></div>
   <div id="wb_Text8" style="position:absolute;left:586px;top:91px;width:65px;height:16px;z-index:23" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Password:</font></div>
   <div id="wb_Text2" style="position:absolute;left:669px;top:116px;width:111px;height:14px;z-index:7" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Remember Me</font></div>
   <div id="wb_Text3" style="position:absolute;left:651px;top:134px;width:122px;height:14px;z-index:9" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Forgot your password?</font></div>

<?php
}
?>



   
   

<div id="copyright" style="position:absolute;left:55px;top:588px;width:150px;height:44px;z-index:32" align="left">
<font style="font-size:13px" color="#000000" face="Arial">Squiblo &#169; 2009</font></div>

<div id="about" style="position:absolute;left:185px;top:588px;width:150px;height:44px;z-index:33" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/about.php"><font color=#000000>About Us</font></a></font></div>

<div id="terms" style="position:absolute;left:285px;top:588px;width:150px;height:44px;z-index:34" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/terms.php"><font color=#000000>Terms and Conditions</font></a></font></div>

<div id="contact" style="position:absolute;left:450px;top:588px;width:150px;height:44px;z-index:35" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/contact.php"><font color=#000000>Contact Us</font></a></font></div>

<div id="privacy" style="position:absolute;left:555px;top:588px;width:150px;height:44px;z-index:36" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/privacy.php"><font color=#000000>Privacy</font></a></font></div>

<div id="help" style="position:absolute;left:640px;top:588px;width:150px;height:44px;z-index:36" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/help.php"><font color=#000000>Help</font></a></font></div>



</div>


</body>
</html>

Link to comment
Share on other sites

You are probably failing to follow the logic of your code. For debugging purposes now and in the future this is something you should learn doing because it will save you a LOT of time when your code is a bit more complex than this one. Try following each step in the process and figure out where things are going wrong. The best way to do this (if there are no apparent error messages) is to print PHP values in strategic places.

Link to comment
Share on other sites

Not sure, why you are using this, i commented it in your code.

$_SESSION['myusername']=$dbusername;

 

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
$_SESSION['myusername'] = $myusername; 
header("location:profile.php");
}
else {
header("location: http://www.squiblo.com/retrylogin.php");
}
}
?>

 

Here you go...

 

<?php
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Squiblo - About Us!</title>
<style type="text/css">
div#container
{
   width: 900px;
   position: relative;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
}
body
{
   text-align: center;
   margin: 0;
}
</style>
</head>
<body bgcolor="#E6E6E6" text="#000000">

<div id="container">
<div id="wb_Shape1" style="position:absolute;left:55px;top:41px;width:792px;height:125px;z-index:2" align="center">
<img src="/Images/header_img.jpg" id="Shape1" align="top" alt="" title="" border="0" width="792" height="125"></div>
<div id="wb_Text1" style="position:absolute;left:60px;top:85px;width:325px;height:72px;z-index:3" align="left">
<font style="font-size:70px" color="#FFFFFF" face="impact"><a href="/index.php" style="text-decoration:none"> <font color="#FFFFFF">SQUIBLO</a></font></font></div>


<div id="wb_Shape2" style="position:absolute;left:54px;top:170px;width:793px;height:412px;z-index:10" align="center">
<img src="/Images/body_img.jpg" id="Shape2" align="top" alt="" title="" border="0" width="793" height="412"></div>


<?php
if($_SESSION['myusername'])){
?>
echo<div id="wb_Text1" style="position:absolute;left:684px;top:55px;width:151px;height:14px;z-index:7" align="right">
<font style="font-size:13px" color="#FFFFFF" face="Arial">You are logged in as:</font><br>
<font style="font-size:15px" color="#FF0000" face="Arial">
</font></div>

<?php
ucwords(strtolower($_SESSION['myusername']));
}
else
{
?>
<form name="form1" method="post" action="checklogin.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
  <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>
   <div id="wb_Text7" style="position:absolute;left:584px;top:66px;width:47px;height:16px;z-index:22" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Username:</font></div>
   <div id="wb_Text8" style="position:absolute;left:586px;top:91px;width:65px;height:16px;z-index:23" align="left">
   <font style="font-size:13px" color="#FFFFFF" face="Arial">Password:</font></div>
   <div id="wb_Text2" style="position:absolute;left:669px;top:116px;width:111px;height:14px;z-index:7" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Remember Me</font></div>
   <div id="wb_Text3" style="position:absolute;left:651px;top:134px;width:122px;height:14px;z-index:9" align="left">
   <font style="font-size:11px" color="#FFFFFF" face="Arial">Forgot your password?</font></div>

<?php
}
?>



   
   

<div id="copyright" style="position:absolute;left:55px;top:588px;width:150px;height:44px;z-index:32" align="left">
<font style="font-size:13px" color="#000000" face="Arial">Squiblo &#169; 2009</font></div>

<div id="about" style="position:absolute;left:185px;top:588px;width:150px;height:44px;z-index:33" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/about.php"><font color=#000000>About Us</font></a></font></div>

<div id="terms" style="position:absolute;left:285px;top:588px;width:150px;height:44px;z-index:34" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/terms.php"><font color=#000000>Terms and Conditions</font></a></font></div>

<div id="contact" style="position:absolute;left:450px;top:588px;width:150px;height:44px;z-index:35" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/contact.php"><font color=#000000>Contact Us</font></a></font></div>

<div id="privacy" style="position:absolute;left:555px;top:588px;width:150px;height:44px;z-index:36" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/privacy.php"><font color=#000000>Privacy</font></a></font></div>

<div id="help" style="position:absolute;left:640px;top:588px;width:150px;height:44px;z-index:36" align="left">
<font style="font-size:13px" color="#000000" face="Arial"><a href="/help.php"><font color=#000000>Help</font></a></font></div>



</div>


</body>
</html>

 

hope this time it will work.

Link to comment
Share on other sites

checklogin.php

<?php
session_start();
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
$_SESSION['myusername'] = $myusername; 
header("location:profile.php");
}
else {
header("location: http://www.squiblo.com/retrylogin.php");
}
}
?>

Link to comment
Share on other sites

From where it is redirecting you to notloggedin.php. i did not see any header to redirect you there.

Plz check your code again. Mb you miss something there.

I m going to bed now...mb somebody will help...but if you need further help, can PM me.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.