469,315 Members | 2,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

how to get request parameter from one php page to another page

3
hello everyone...
myself Nawaz from Mangalore...

I've created a web page using jsp.. now i want to convert it to php.... so please help me out... i want to know how to pass parameter to another page and get request from the previous page... u can give with example.... like i want to create a login page... now user will enter his/her id and password... i want to check whether its a valid one or not.. if its a valid one then it should go to another page.. else stay in current page... so please help me in solving this problem...

Nawaz
Sep 26 '06 #1
4 38975
skim
9
Using "SESSIONS"
For example,
test1.php
<?php
session_start();
$_SESSION['logPass']="whatever";
.
.
.
Your Code
.
.
.
?>
test2.php
<?php
session_start();
$pass = $_SESSION['logPass'];
echo $pass;
?>
Output
whatever

Please read session part.
I hope this is what you want.
Sep 26 '06 #2
naja
3
Hi skim,,
I'll provide u the 2 pages i've created using jsp javascript for login page... check it out... and let me know how can i do it in php....check only the code which is bold..so it'll be easy for u...ok

page 1......

<html>
<head>
<title>MRPL management Staff Association</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
@import url("images/css.css");
@import url("images/styles.css");
body {
background-color: #999999;
}
.style1 {color: #FFFFFF}
.style2 {font-size: 9px}
.style6 {font-size: 12px}
.style7 { font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (template2.psd) -->
<table width="778" height="629" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
<td width="265"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="264" height="118">
<param name="movie" value="images/logo1.swf">
<param name="quality" value="high">
<embed src="images/logo1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="264" height="118"></embed>
</object></td>
<td>
<img src="images/index1_02.gif" width="514" height="118" alt=""></td>
</tr>
<tr>
<td height="57" colspan="2" background="images/index_03.jpg">&nbsp;</td>
</tr>
<tr>
<td height="153" colspan="2" valign="middle" style="border-bottom:bd2827 solid 1px;"><script type="text/javascript">


//Specify the slider's width (in pixels)
var sliderwidth="778px"
//Specify the slider's height
var sliderheight="153px"
//Specify the slider's slide speed (larger is faster 1-10)
var slidespeed=3
//configure background color:
slidebgcolor="#EAEAEA"

//Specify the slider's images
var leftrightslide=new Array()
var finalslide=''
leftrightslide[0]='<img src="images/image1.jpg" border=1>'
leftrightslide[1]='<img src="images/image2.jpg" border=1>'
leftrightslide[2]='<img src="images/image3.jpg" border=1>'
leftrightslide[3]='<img src="images/image4.jpg" border=1>'
leftrightslide[4]='<img src="images/image5.jpg" border=1>'

//Specify gap between each image (use HTML):
var imagegap=" "

//Specify pixels gap between each slideshow rotation (use integer):
var slideshowgap=5


////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(imageg ap)+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide

function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftr ightslide
actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+slideshowgap+" px"
}
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slideme nu2
ns_slide2=document.ns_slidemenu.document.ns_slidem enu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+slideshowgap
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
}
lefttime=setInterval("slideleft()",30)
}
window.onload=fillup

function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style. left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style .left)+actualwidth+slideshowgap+"px"

if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.styl e.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style .left)+actualwidth+slideshowgap+"px"

}
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+slideshow gap

if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+slideshow gap
}
}


if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+sliderwidth+';hei ght:'+sliderheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+sliderwidth+';hei ght:'+sliderheight+';background-color:'+slidebgcolor+'" onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3" style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'>')
write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script></td>
</tr>
<tr>
<td height="277" align="center" valign="top" bgcolor="0c5386" class="date"><table width="90%" border="0">
<tr>
<td align="center" valign="middle" class="text"><p align="center" class="title style1">Members Login</p>
<form name="form3" method="post" action="http://localhost:8080/mrpl/login.jsp" onSubmit = "return validate(this.form)">
<p class="style1">
<label>Login_Id&nbsp;
<input type="text" name="login_id" tabindex="1">
</label>
</p>
<p class="style1">
<label>Password
<input type="password" name="password" tabindex="2">
</label>
</p>
<p>
<span class="style1">
<LABEL></LABEL>
</span> <span class="style1">
<center>
<input type="submit" value="Submit" tabindex="3" name="Submit">
</center>
&nbsp;&nbsp; </span></p>
</FORM>
</td>
</tr>
</table>
<p><span class="style7">MRPL <br>
Management </span><span class="style7">Staff Association</span><br>
(Registration No. TUA 484: 2005)</p>
<p class="style6"> Room No.4, <br>
1st Floor, MRPL Employees Club, <br>
Kuthethoor
P.O., Mangalore 575 030.<br>
Karnataka India</p>
<p class="style6">Contact Nos.: <br>
0824 2236649 (Dir) <br>
2270400 Extn 4649 </p></td>
<td width="517" height="277" align="center" valign="top" bgcolor="006cb0" class="text style1"><TABLE width="90%" align="center">
<TBODY>
<TR>
<TD align="center" valign="middle" class="text style1"><p align="left" class="title style1">About Us</p>
<p align="center"><em>Real strength never impairs beauty or harmony, but it often bestows it; and in everything imposingly beautiful, strength has much to do with the magic.</em></p>
<p align="right"><em>- Herman Melville</em></p>
<p align="justify"> MRPL management staff association is a body comprising of management staff of Mangalore Refinery and Petrochemicals Ltd. At present there are more than 270 management staff personnel who are members of this August body. It is mutual trust, even more than mutual interest that binds the members of our association<br>
The main objectives of the association are</p>
<ul>
<li>
<div align="justify"> To have direct and effective channel of communication with the Management and there by improve the efficiency, profitability and development of the Company.</div>
</li>
<li>
<div align="justify">
To discuss, debate and ensure improvement of welfare and service conditions of the members of the Association.</div>
</li>
<li>
<div align="justify">
To foster unity, goodwill, understanding and harmony among the<br>
members and promote mutual help and appreciation.</div>
</li>
<li>
<div align="justify">
To promote harmonious relation between management and non- management staff.</div>
</li>
<li>
<div align="justify">
To seek affiliation with All India Organization/Association of the management staff in the Oil industry having similar objectives.</div>
</li>
</ul></TD>
</TR>
<TR>
<TD align="center" valign="middle" class="text style1">&nbsp;</TD>
</TR>
</TBODY>
</TABLE></td>
</tr>
<tr>
<td height="24" colspan="2" background="images/index_07.jpg" class="text style1"><div align="center" class="style2">Copyright @ MRPL Management Staff Association, all rights reserved designed by : Jyothi Software Solutions </div></td>
</tr>
</table>
</body>
</html>
Sep 27 '06 #3
naja
3
thi is the second page.....

page 2......

<%@ page import="java.sql.*" %>
<%

String log_id = request.getParameter("login_id");
String pwrd = request.getParameter("password");
//out.println(loginname)
String uname;
String upwd;

try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mrplkana"," tiger","manager");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from logintbl");

while(rs.next())
{
uname=rs.getString(1);
upwd=rs.getString(2);


if(log_id.equals(uname) && pwrd.equals(upwd))
{
response.sendRedirect("http://localhost:8080/mrpl/news.html");
}
else
{%>
<script language="javascript">
alert("WRONG USER NAME OR PASSWORD.");

document.location.href="http://localhost:8080/mrpl/index.html";
</script>
<% }

}


}




catch(Exception e)
{
out.println(e.getMessage());
}
%>
Sep 27 '06 #4
skim
9
I think you need to read a session document.
http://www.w3schools.com/php/php_sessions.asp
http://www.tizag.com/phpT/phpsessions.php

In PHP, you need containers to send parameters to next pages.
So, you want to send "login_id" and "password" on 'POST' method to the next page, then do this.

session_start(); // Start Session. It's required.
$_SESSION['login_id'] = $_POST['login_id']; //Put 'login_id' text from the form into the session container
$_SESSION['password'] = $_POST['password']; //Put 'password' into the another container as the 'login_id'
Done!!!

The session will remember values in everywhere on your script.
Now, how to open the session variables
Any next pages.
session_start(); // Start Session. It's required.
$login_id = $_SESSION['login_id']; // indicate what 'login_id' value is
$password = $_SESSION['password']; // indicate what "password' value is
Done!!!

P.S: You do not need 2 pages to check the legal user. Try to use this way.
session_start();
if(isset($_POST['Submit']))
{
//check user here and if the user is legal
if(user is legal)
{
//if you still want to send user id to next page
$_SESSION['login_id'] = $_POST['login_id'];
$_SESSION['password'] = $_POST['password'];
// do whatever or go to next page
}
else
{
print "Sorry you are not legal user";
}

}

I hope this helps you.
Sep 27 '06 #5

Post your reply

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

Similar topics

8 posts views Thread by turnit \(removethis\) | last post: by
7 posts views Thread by Aaron Prohaska | last post: by
10 posts views Thread by Bo Rasmussen | last post: by
reply views Thread by Frank 'Olorin' Rizzi | last post: by
6 posts views Thread by Ammar | last post: by
6 posts views Thread by Steve | last post: by
1 post views Thread by C. (http://symcbean.blogspot.com/) | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.