Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Displaying change in session variable withoud reloading page
Old 06-02-2009, 10:03 AM Displaying change in session variable withoud reloading page
Junior Talker

Posts: 3
Name: David Robertson
Trades: 0
Ok,

Im very new to web design. I started building this website 2 weeks ago, so I hope this question is a lot easier than the difficulty its giving me.

Basically, I have three pages of code of importance here.
1.Main.php
2.Members.html
3.Login.php

The Main.php page is basically the home page. It is divided into 7 sections using div tags. Within one of these sections is an iframe, whereby you can login to the website. The login page that the iframe is showing is Members.html. When you enter your username and password, and hit submit, the data gets sent to Login.php, where it checks against the database to make sure your a member. If you are, it Login.php displays your account balance. That all works great. The problem here is this;

Back on the Main.php page, in another div section, i want to display a message which says one of two things, depending if your logged in or not.
a) not logged in: Welcome, please login.
b) logged in: Welcome, username.

Now, the code I wrote for this section of the main.php shows Welcome, please login, when you open it up. After you login through the iframe however, it doesn't change, because only the iframe has been refreshed, and not the whole main.php. However, after logging in, if you refresh main.php, the welcome, username does show up.

Now, obviously, I want the welcome, username message to show without having to refresh main.php, but cant find anywhere on the web to show me. Please someone help cause this is driving me crazy. Below is the code for each important part of the pages.
cheers


1.Main.php
here is the code for the div where i want the personalised message and the code for the div with the iframe

<div id = "welcome">
<?
if(isset($_SESSION['Username']))
echo "".$_SESSION[Username];
else
echo welcome;
?>
</div>


<div id = "login"><iframe members="members" src="members.html" frameborder="0" width="438" height="60"></iframe>
</div>


2.Members.HTML
I dont think showing this is necessary, its just a form that gets posted to Login.php.


3.Login.php
This is the code after i am logged into database

If ($num_rows<1){
echo "<script language=javascript>alert('The user information you have entered is incorrect.')</script>";
echo"<script>document.location.href='members.html' </script>";
}
else {
$SQL = "SELECT * FROM accountbalance WHERE Username = '$Username'";
$result = mysql_query($SQL);
$db_field = mysql_fetch_assoc($result);
$Balance = $db_field['Balance'];


session_start();
$_SESSION['Username']=$Username;
$_SESSION['Balance']=$Balance;
header("Location:members.php");
$query = "INSERT INTO usersloggedin (Username) VALUES ('$Username')";
mysql_query($query) or die(mysql_error());
mysql_close();

}
}
else {
echo "<script language=javascript>alert('There was a problem connecting with the database.')</script>";
mysql_close();
}
drob2689 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-02-2009, 11:21 AM Re: Displaying change in session variable withoud reloading page
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
need to see the entire code from each page

if your refreshing the page for a value to show then this points to a misplacement code block

for example

Look at this example

//// mypage.php

SELECT statement

UPDATE statement

/////

Now if i perform an update and display the results i wont see the update until i refresh the page. If i swap them around with UPDATE first then id see the update as the page was returned
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 06-02-2009, 11:42 AM Re: Displaying change in session variable withoud reloading page
Junior Talker

Posts: 3
Name: David Robertson
Trades: 0
Ok, thanks for the reply, although i didnt quite understand it as i am still a novice. Below is the entire code of each three pages. I forgot to mention 1 other page....members.php .......which the iframe returns on a succesgul login. Login php just processes the username and passwoed then returns members.php in the frame. I haven't shown members.php below because i dont think its relevant to the question.

So re-iterating, bassiacally, when the member logs in through the iframe on Main.php, if succeful, i need another part of main.php to update, without reloading the page to reflect the username.

cheers



Main.php

<?php
// this starts the session
session_start();
?>


<html>
<head>
<title>layout</title>

<style type = "text/css">
div#welcome {position:absolute; top:0px; left:559px; width:440px; height:20px; border:1px black solid; background-color:rgb(132,165,191);}
div#login {position:absolute; top:20px; left:559px; width:440px; height:60px; border:1px black solid; background-color:green;}
div#links1 {position:absolute; top:0px; left:10px; width:550px; height:20px; border:1px black solid; background-color:rgb(243,248,251);}
div#header {position:absolute; top:20px; left:10px; width:550px; height:60px; border:1px black solid;}
div#links2 {position:absolute; top:79px; left:10px; width:989px; height:20px; border:1px black solid; background-color:rgb(10,110,186);}}
div#nav {position:absolute; top:99px; left:10px; width:175px; height:440px; border:1px black solid;}
div#body {position:absolute; top:99px; left:184px; width:815px; height:440px; border:1px black solid; overflow:scroll;}
a.login:link {cursorointer; color:blue; text-decoration:none; font-size:10pt; font-style:bold;}
a.login:visited {cursorointer; color:blue; text-decoration:none; font-size:10pt; font-style:bold;}
a.login:hover{cursorointer; color:blue; text-decoration:none; font-size:10pt; font-style:bold;}
a.login:active {cursorointer; color:blue; text-decoration:none; font-size:10pt; font-style:bold;}
a.links1:link {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
a.links1:visited {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
a.links1:hover{cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:normal;}
a.links1:active {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
</style>

</head>

<body OnUnload = "alert('goodbye')";>

<div id = "welcome">
<?
if(isset($_SESSION['Username']))
echo "".$_SESSION[Username];
else
echo welcome;
?>

</div>

<div id = "login"><iframe members="members" src="members.html" frameborder="0" width="438" height="60"></iframe>
</div>

<div id = "links1">&nbsp;&nbsp;&nbsp;<a href="openaccount.html" target="_blank" class="links1">Open an Account</a>&nbsp;&nbsp;&nbsp;<img src=dline.bmp align=middle>&nbsp;&nbsp;&nbsp<a href="about us.html" target="_blank" class="links1">About Us</a>&nbsp;&nbsp;&nbsp;<img src=dline.bmp align=middle>&nbsp;&nbsp;&nbsp<a href="help.html" target="_blank" class="links1">Help</a>&nbsp;&nbsp;&nbsp;<img src=dline.bmp align=middle>&nbsp;&nbsp;&nbsp<a href="responsible gambling.html" target="_blank" class="links1">Responsible Gambling</a>
</div>

<div id = "header"><img src=logo.bmp></div>

<div id = "links2">links2</div>

<div id = "nav">nav</div>

<div id = "body"><img src=kitten.jpg></div>

</body>

</html>





Members.html

<html>
<head>
<title>main</title>
<style type="text/css">
a.links1:link {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
a.links1:visited {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
a.links1:hover{cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:normal;}
a.links1:active {cursorointer; color:rgb(69,122,196); text-decoration:none; font-size:10pt; font-style:bold;}
</style>

</head>
<body bgcolor=rgb(243,248,251) style="vertical-align:top; padding:0px; margin:0px;">


<form Name="login" method="post" action="login.php">
<table border="0" cellpadding="0" cellspacing="0" valign="top">
<tr>
<td style="font-family:callibri; font-size:12px; text-align:right; vertical-align:middle; padding-right:3px; padding-left:2px;">username</td>
<td style="padding-bottom:0px;"><input type="text" size=20 value="" name=Username style="height:17px; width:90px; margin-top:0px;"></td>
<tdstyle="padding-bottom:0px;"> </td>
</tr>
<tr>
<td style="font-family:callibri; font-size:12px; text-align:right; vertical-align:middle; padding-right:3px; padding-left:2px;">password</td>
<td style="padding-bottom:0px;"><input type="text" size=20 value="" name=Password1 style="height:17px; width:90px;"</td>
<td style="padding-bottom:0px;"><input type=submit value="Login" style="height:20px; width:45px; font-size:10px;" </td>
</tr>
</form>
<tr>
<td style="padding-left:2px;">&nbsp&nbsp&nbsp <a href="registration.html" class="links1">Register</a>&nbsp&nbsp</td>
<td> <img src=dline.bmp align=middle>&nbsp&nbsp<a href="forgot.html" class="links1">Forgot Password?</a></td>

</tr>
</table>
</body>
</html>



Login.php

<?PHP
$Username=$_POST['Username'];
$Password1=$_POST['Password1'];
$user_name="jeupcom_david";
$password="xxxxxxxxx";
$database="jeupcom_tip";
$server="localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM users WHERE Username='$Username' AND Password1='$Password1'";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);


If ($num_rows<1){
echo "<script language=javascript>alert('The user information you have entered is incorrect.')</script>";
echo"<script>document.location.href='members.html' </script>";
}
else {
$SQL = "SELECT * FROM accountbalance WHERE Username = '$Username'";
$result = mysql_query($SQL);
$db_field = mysql_fetch_assoc($result);
$Balance = $db_field['Balance'];


session_start();
$_SESSION['Username']=$Username;
$_SESSION['Balance']=$Balance;
header("Location:members.php");
$query = "INSERT INTO usersloggedin (Username) VALUES ('$Username')";
mysql_query($query) or die(mysql_error());
mysql_close();

}
}
else {
echo "<script language=javascript>alert('There was a problem connecting with the database.')</script>";
mysql_close();
}
?>
drob2689 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Displaying change in session variable withoud reloading page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44335 seconds with 12 queries