saleemkhan
asked on
how to submit variable to a php page?
hi all ,
i am trying to fetch the data from a php page and
do the backend process in jsp page and then submit the result to php page. i am using URLConnection .
code in login.php
<form action="http://abc.com/process.jsp" method="post">
<input name="un" type="text">
<input name="pass" type="password">
<input type="submit" value="Submit">
</form>
code in process.jsp
String un=null;
String pass=null;
un=request.getParameter("u
out.print("un="+un);
pass=request.getParameter(
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
String myurl="http://xyz.com/xyz/result.php?result="+result;
out.print("myurl="+myurl);
URL u = new URL(myurl);
URLConnection yc= u.openConnection();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt
html.close();
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
code in result.php
<?php
echo "<br>";
echo "result=";
echo $_REQUEST['result'];
echo "<br>";
?>
my problem is i am unable to print the result fetch from jsp.i think there is some problem in submitting the variable to a php page? am i in the right way? or guide me where i am wrong?
waiting for expert solution.?
ASKER
hi jarasa,
i am trying to print the value in result.php.its a boolean value.
i am trying to print the value in result.php.its a boolean value.
you don't read the results from the php:
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt ream()));
String line = null;
while (null!=(line=html.readLine ()))
{
out.println(line);
}
html.close();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt
String line = null;
while (null!=(line=html.readLine
{
out.println(line);
}
html.close();
ASKER
hi objects,
>> you don't read the results from the php:
>> BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt ream()));
>> String line = null;
>> while (null!=(line=html.readLine ()))
>>{
>> out.println(line);
>> }
>.html.close();
what the above code will do?have u got me problem?my problem is i cant able to print the result in result.php.(i cant see the result value in result.php its blank).
waiting for expert solution
>> you don't read the results from the php:
>> BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt
>> String line = null;
>> while (null!=(line=html.readLine
>>{
>> out.println(line);
>> }
>.html.close();
what the above code will do?have u got me problem?my problem is i cant able to print the result in result.php.(i cant see the result value in result.php its blank).
waiting for expert solution
> what the above code will do?
It reads the results from the php page and returns it to browser.
It reads the results from the php page and returns it to browser.
ASKER
hi objects,
i dont want to read results from a php page.i want to throw the result from my jsp page to php.
And in php page i want to display(print) the result.
Am i in right direction?
i dont want to read results from a php page.i want to throw the result from my jsp page to php.
And in php page i want to display(print) the result.
Am i in right direction?
> Am i in right direction?
Doesn't sound like it, at the moment your jsp page is calling your php page.
Doesn't sound like it, at the moment your jsp page is calling your php page.
ASKER
hi objects,
Let me explain you what i am trying to do.
1)A php page(login.php) username and password will submit to my jsp file.
code :
<form action="http://abc.com/process.jsp" method="post">
<input name="un" type="text">
<input name="pass" type="password">
<input type="submit" value="Submit">
</form>
2)My jsp page fetch username and password and do process and then submit the result to result.php
code :
code in process.jsp
String un=null;
String pass=null;
un=request.getParameter("u n");
out.print("un="+un);
pass=request.getParameter( "pass");
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
String myurl="http://xyz.com/xyz/result.php?result="+result;
out.print("myurl="+myurl);
URL u = new URL(myurl);
URLConnection yc= u.openConnection();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt ream()));
html.close();
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
as per your comment i understand that i am calling a php page.
I think i have to use outputstream or anyother method to submit the result to result.php.
am i right?
if not correct me.
and in result.php i just want to print the value
code in result.php
<?php
echo "<br>";
echo "result=";
echo $_REQUEST['result'];
echo "<br>";
?>
am i right?
if not correct me.
Let me explain you what i am trying to do.
1)A php page(login.php) username and password will submit to my jsp file.
code :
<form action="http://abc.com/process.jsp" method="post">
<input name="un" type="text">
<input name="pass" type="password">
<input type="submit" value="Submit">
</form>
2)My jsp page fetch username and password and do process and then submit the result to result.php
code :
code in process.jsp
String un=null;
String pass=null;
un=request.getParameter("u
out.print("un="+un);
pass=request.getParameter(
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
String myurl="http://xyz.com/xyz/result.php?result="+result;
out.print("myurl="+myurl);
URL u = new URL(myurl);
URLConnection yc= u.openConnection();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt
html.close();
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
as per your comment i understand that i am calling a php page.
I think i have to use outputstream or anyother method to submit the result to result.php.
am i right?
if not correct me.
and in result.php i just want to print the value
code in result.php
<?php
echo "<br>";
echo "result=";
echo $_REQUEST['result'];
echo "<br>";
?>
am i right?
if not correct me.
Try this to make a test:
<%
String un=null;
String pass=null;
un=request.getParameter("u n");
out.print("un="+un);
pass=request.getParameter( "pass");
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
%>
<html>
<head>
</head>
<Body onLoad="top.location.href= 'http://xyz.com/xyz/result.php?result='<%=result %>;">
</Body>
</html>
<%
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
%>
Javier
<%
String un=null;
String pass=null;
un=request.getParameter("u
out.print("un="+un);
pass=request.getParameter(
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
%>
<html>
<head>
</head>
<Body onLoad="top.location.href=
</Body>
</html>
<%
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
%>
Javier
ASKER
hi javier,
i tried your comment. it just prints username and password
process.jsp and thats all.
where i am wrong.
i tried your comment. it just prints username and password
process.jsp and thats all.
where i am wrong.
What happens if you put on your browser directly the URL http://xyz.com/xyz/result.php?result=true?
Javier
Javier
Sorry you said a boolean
http://xyz.com/xyz/result.php?result=0
Javier
http://xyz.com/xyz/result.php?result=0
Javier
ASKER
if i put the url directly i will print
result=0
And this?
String un=null;
String pass=null;
un=request.getParameter("u n");
out.print("un="+un);
pass=request.getParameter( "pass");
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
String myurl="http://xyz.com/xyz/result.php?result="+result.toString() ;
out.print("myurl="+myurl);
URL u = new URL(myurl);
URLConnection yc= u.openConnection();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt ream()));
html.close();
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
String un=null;
String pass=null;
un=request.getParameter("u
out.print("un="+un);
pass=request.getParameter(
out.print("pass="+pass);
boolean result=false;
if ("un1".equals(un) && "un1".equals(pass))
{
result =true;
}
else
{
result=false;
}
String myurl="http://xyz.com/xyz/result.php?result="+result.toString()
out.print("myurl="+myurl);
URL u = new URL(myurl);
URLConnection yc= u.openConnection();
BufferedReader html = new BufferedReader(new InputStreamReader(u.openSt
html.close();
} catch (Exception e) {
out.print("There is a connectionproblem: " +e.getMessage());
}
ASKER
compile error cannot invoke toString on a primitive type boolean
at line
String myurl="http://xyz.com/xyz/result.php?result="+result.toString() ;
at line
String myurl="http://xyz.com/xyz/result.php?result="+result.toString()
I can't understand that:
toString() -> Returns a String object representing this Boolean's value.
Opps I see:
Change this:
boolean result=false;
For this
Boolean result=false;
And try again please
Javier
toString() -> Returns a String object representing this Boolean's value.
Opps I see:
Change this:
boolean result=false;
For this
Boolean result=false;
And try again please
Javier
ASKER
i tried your comment,
i am getting error typemismatch error cannot from boolean to java.lang.Boolean.
i am getting error typemismatch error cannot from boolean to java.lang.Boolean.
Ok Lets do this and if it works we try to fix it.
Put this line on your original code:
String myurl="http://xyz.com/xyz/result.php?result=0";
Sorry for the errors but I don't have time to make the validations here.
Javier
Put this line on your original code:
String myurl="http://xyz.com/xyz/result.php?result=0";
Sorry for the errors but I don't have time to make the validations here.
Javier
ASKER
i tried your comment,
but no success.
explanation:-
Whats happens here is when i submit username and password from login.php it goes to process.jsp
its prints like this
un=un1pass=un1
myurl=http://xyz.com.com/xyz/result.php?result=0
why it wont redirect to result.php and display the result there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use _GET instead of _REQUEST in your php!
HTH
HTH
>use _GET instead of _REQUEST in your php!
Can't be that Silly :c))
I have to say that know nothing about PHP tho.
If he is getting the out.print() does not mean that the redirection is not working??
Javier
Can't be that Silly :c))
I have to say that know nothing about PHP tho.
If he is getting the out.print() does not mean that the redirection is not working??
Javier
>Can't be that Silly :c))
I mean the solution not you!!!
:c)
Javier
I mean the solution not you!!!
:c)
Javier
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I always have this problem is like the AND && and OR || always mismatch them.
true is 0 and false is 1 or viceversa??
Javier
true is 0 and false is 1 or viceversa??
Javier
hmm. I think for shell, 0 is success, otherwise fail. any other language I came across is true-1, false-0. but I could be wrong, I'm silly :-)
Well I'm serious Kenneth I alway mismatch that. I say that becose of my previous post:
Should be this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"0":"1");
or this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"1":"0");
Javier
Should be this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"0":"1");
or this way:
String myurl="http://xyz.com/xyz/result.php?result="+(result?"1":"0");
Javier
saleemkhan, Javier's solution is very close to the answer. He should get points not me. (I don't thin i'll get but just in case :-)
Kenneth, I'm not here for the points, and besides I made too many obvious mistakes in this question, I guess he should split them.
I've learned too today :c)
Javier
I've learned too today :c)
Javier
ASKER
hi,
i split the points.i dont have idea who got 125 and who got 50-:)
i am sorry if i make a mistake in spliting points -:)
i split the points.i dont have idea who got 125 and who got 50-:)
i am sorry if i make a mistake in spliting points -:)
Is OK :c)
Thanks
Javier
Thanks
Javier
ASKER
your welcome -:)
any contact email -:)
any contact email -:)
Javier