By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

variable cannot be passed to multiple pages.

P: 32
i have designed a login page like this:

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Electrical Engineering Dept IITK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {font-size: 14px}
.style3 {font-size: 18px}
.style4 {font-size: 24px}
.style5 {font-size: 36px}
-->
</style>
</head>

<body bgcolor="#99CCFF">
<form name="form1" method="post" action="../myphp/validate1.php">
<div align="center">
<p> <span class="style1">
</span></p>
<pre><span class="style1"><span class="style2"><span class="style3"><span class="style4"><span class="style5"><label><u>Electrical Engineering Department IIT-KANPUR</u></label></span></span></span></span></span></pre>
<p>&nbsp;</p>
<p><span class="style1"> </span> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="38%" border="0">
<tr>
<th scope="row"><div align="left">
<label>User Name</label>
&nbsp;</div></th>
<td><input name="username" type="text" size="35" maxlength="35"></td>
</tr>
<tr>
<th height="29" scope="row"><div align="left">Password</div></th>
<td><input name="password" type="password" size="35" maxlength="35"></td>
</tr>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;
<p>&nbsp;</p>
<table width="2%" border="0" align="center">
<tr>
<th scope="row"><input type="submit" name="Submit" value="Login"></th>
<td><input type="submit" name="Submit2" value="Cancel"></td>
</tr>
</table>
<p>&nbsp;</p>

<label><u><strong></strong></u></label>
</p>
</div>
</form>
</body>
</html>[/HTML]

this page is calling validate.php which is :

[PHP]<?php
session_start();
$passwords = array("ajohari" =>"anurag",
"knaveen" =>"naveen",
"pkk" =>"kalra",
"anu" =>"anu");
if ($password == $passwords[$username]){
$_SESSION['user']=$username?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Faculy Information of E.E Depatment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<frameset rows="144,*" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="frame1.php" name="topFrame" scrolling="NO" noresize >
<frameset rows="*" cols="257,*" framespacing="0" frameborder="NO" border="0">
<frame src="frame2.php" name="leftFrame" scrolling="NO" noresize>
<frame src="frame3.php" name="mainFrame">
</frameset>
</frameset>
</html>
<?
exit();
}else{
echo "<H2>Invalid user name or password: access denied.</H2>";
include("../myphp/eeiitk.php");
}
?>[/PHP]

after validating frame3.php page is called which is:

[PHP] <?php
session_start();
$connection = pg_connect("host=localhost dbname=personal user=postgres");
if (!$connection) {
print("Connection Failed.");
exit;
}
$username1=$_SESSION['user'];

$myresult = pg_exec($connection, "SELECT * FROM personal where username='username1'");

for ($lt = 0; $lt < pg_numrows($myresult); $lt++) {
$name = pg_result($myresult, $lt, 0);
$designation = pg_result($myresult, $lt, 1);
$department = pg_result($myresult, $lt, 2);
$telephonework = pg_result($myresult, $lt, 3);
$telephoneres = pg_result($myresult, $lt, 4);
$fax = pg_result($myresult, $lt, 5);
$email = pg_result($myresult, $lt, 6);
$address = pg_result($myresult, $lt, 7);
$areaofinterest = pg_result($myresult, $lt, 8);
$username= pg_result($myresult, $lt, 9);
$image= pg_result($myresult, $lt, 10);
}
?>

<body bgcolor="#FFCC99">
<form name="form1" method="post" action="pupdate.php">
<p>&nbsp;</p>
<table width="575" border="0" cellpadding="1" cellspacing="1">
<tr>
<th width="148" scope="row"><div align="left">
<label>IMAGE</label>
</div></th>
<td width="361">
<div align="center">
<input name="image" type="image" src="../naveen_iitk/photos/pkkalra.jpg" width="320" height="240" border="0">
</div>
</td>
<td width="66">
<div align="center">
<input type="submit" name="Submit" value="Upload">
</div>
</td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>USERNAME</label>
</div></th>
<td>
<div align="left">
<input name="username" type="text" size="60" maxlength="50" readonly="" value="<? echo "$username"; ?>">
</div>
</td>
<td></td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>NAME</label>
</div></th>
<td>
<div align="left">
<input name="name" type="text" size="60" maxlength="50" value="<? echo "$name"; ?>">
</div>
</td>
<td></td>
</tr>
<tr>
<th scope="row">
<div align="left">
<label>DESIGNATION</label>
</div></th><td><div align="left">
<input name="designation" type="text" size="60" maxlength="50" value="<? echo "$designation"; ?>">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>DEPARTMENT</label>
</div></th>
<td>
<div align="left">
<input name="department" type="text" size="60" maxlength="50" value="<? echo "$department"; ?>">
</div>
</td>
<td></td>
</tr>
<tr>
<th scope="row"><div align="left"><label>TELEPHONE(Work)</label>
</label>
</div></th><td><div align="left">
<input name="telephonework" type="text" size="60" maxlength="50" value="<? echo "$telephonework"; ?>">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><div align="left"><label>TELEPHONE (Res)</label>
</label>
</div></th><td><div align="left">
<input name="telephoneres" type="text" size="60" maxlength="50" value="<? echo "$telephoneres"; ?>">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>FAXNO.</label>
</div></th>
<td><div align="left">
<input name="fax" type="text" size="60" maxlength="50" value="<? echo "$fax"; ?>">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>EMAIL</label>
</div></th>
<td><div align="left">
<input name="email" type="text" size="60" maxlength="50" value="<? echo "$email"; ?>">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><div align="left">
<label>ADDRESS</label>
</div></th>
<td>
<div align="left">
<textarea name="address" cols="46" rows="5"><? echo "$address"; ?></textarea>
</div>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<th height="150" scope="row">
<div align="left">
<label>AREA OF INTEREST</label>
&nbsp;</div></th>
<td><div align="left">
<textarea name="areaofinterest" cols="46" rows="8"><? echo "$areaofinterest";?></textarea>
</div>
</td>
<td>&nbsp;</td>
</tr>
</table>
<div align="center">
<input type="submit" name="submit" value="Update">
<input type="reset" name="reset" value="Clear It">
</label>
</label>
</div>
</form>
</body>
</html>[/PHP]


But the session_start is not working. The data from the table is not fetched.
Can u tell me that where I m going wrong.
Feb 6 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Oh yes, these variables can, and indeed are, passed to the script. But you have not assigned the passed POSTed values for username and password the the appropriate variables.

Script validate.php must begin as follows:

[php]<?php
session_start();
$username = trim(strip_tags($_POST['username']));
$password = trim(strip_tags($_POST['password']));
// ... etc ...[/php]
Ronald :cool:
Feb 6 '07 #2

P: 32
It is not working.
How can I pass tee variable in different scripts?
Please help!
Feb 7 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
I am sure it works but somehow you don't handle the POSTed values not correctly. Show the code.

Ronald :cool:
Feb 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.