?
Solved

how to submit variable to a php page?

Posted on 2004-03-25
33
Medium Priority
?
277 Views
Last Modified: 2010-04-01

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("un");
                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.openStream()));
                  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.?

0
Comment
Question by:saleemkhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 11
  • 5
  • +1
33 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 10676051
What are you expecting to get on the php a boolean, a textString or a number?

Javier
0
 

Author Comment

by:saleemkhan
ID: 10676121
hi jarasa,
  i am trying to print the value in result.php.its a boolean value.
0
 
LVL 92

Expert Comment

by:objects
ID: 10676387
you don't read the results from the php:

  BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
  String line = null;
  while (null!=(line=html.readLine()))
  {
      out.println(line);
  }
  html.close();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:saleemkhan
ID: 10676422
hi objects,
 >>  you don't read the results from the php:

 >> BufferedReader html = new BufferedReader(new InputStreamReader(u.openStream()));
 >> 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


0
 
LVL 92

Expert Comment

by:objects
ID: 10676431
> what the above code will do?

It reads the results from the php page and returns it to browser.
0
 

Author Comment

by:saleemkhan
ID: 10676459
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 10676471
> Am i in right direction?

Doesn't sound like it, at the moment your jsp page is calling your php page.
0
 

Author Comment

by:saleemkhan
ID: 10676518
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("un");
                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.openStream()));
                  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.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676532
Try this to make a test:
<%
String un=null;
                String pass=null;
                un=request.getParameter("un");
                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
0
 

Author Comment

by:saleemkhan
ID: 10676637
hi javier,
    i tried your comment. it just prints username and password
 process.jsp and thats all.


where i am wrong.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676711
What happens if you put on your browser directly the URL http://xyz.com/xyz/result.php?result=true?

Javier

0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676719
Sorry you said a boolean
http://xyz.com/xyz/result.php?result=0
Javier

0
 

Author Comment

by:saleemkhan
ID: 10676744

if i put the url directly i will print

result=0
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676761
And this?

String un=null;
                String pass=null;
                un=request.getParameter("un");
                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.openStream()));
                  html.close();



            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }
0
 

Author Comment

by:saleemkhan
ID: 10676799
compile error cannot invoke toString on a primitive type boolean
at line
String myurl="http://xyz.com/xyz/result.php?result="+result.toString();
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10676851
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

0
 

Author Comment

by:saleemkhan
ID: 10677222
i tried your comment,
 i am getting error typemismatch error cannot from boolean to java.lang.Boolean.

0
 
LVL 6

Expert Comment

by:jarasa
ID: 10677625
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
0
 

Author Comment

by:saleemkhan
ID: 10677886

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.

0
 
LVL 6

Assisted Solution

by:jarasa
jarasa earned 375 total points
ID: 10678075
OK I checked this one, :c)

<%
String un=null;
String pass=null;
un=request.getParameter("un");
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?"0":"1");
out.print("myurl="+myurl);
response.sendRedirect(myurl);

%>

Javier
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10678099
use _GET instead of _REQUEST in your php!
HTH
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678156
>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
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678172
>Can't be that Silly :c))

I mean the solution not you!!!

:c)

Javier
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 150 total points
ID: 10678855
You might be right, Javier! It was silly. I realized that you onload idea should have worked but there was some typo
try this:
<%
String un=null;
                String pass=null;
                un=request.getParameter("un");
                // out.print("un="+un);
                pass=request.getParameter("pass");
                // out.print("pass="+pass);
                int result=0;
               if ("un1".equals(un) && "un1".equals(pass))
                {
                  result =1;
                }
               else
               {
                  result=0;
                }
    response.sendRedirect( "http://xyz.com/xyz/result.php?result=" + result );
            } catch (Exception e) {

                  out.print("There is a connectionproblem: " +e.getMessage());

            }
%>
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10678941
I always have this problem is like the AND && and OR || always mismatch them.
true is 0 and false is 1 or viceversa??

Javier
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10678991
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 :-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10679085
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

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10679229
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10679282
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 :-)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10679376
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
0
 

Author Comment

by:saleemkhan
ID: 10712126
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 -:)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10712135
Is OK :c)
Thanks
Javier
0
 

Author Comment

by:saleemkhan
ID: 10712160
your welcome -:)

any contact email -:)
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question