How can I Pass Variable from JApplet to PHP?

I try to send variable for applet to php but the result is no data was recorded in my database.
I think the data did not transfer to php.
I am familiar with php but new to java.
Can someone help me?
public class test extends JApplet {
     public test(){
           JButton myButton = new JButton("sendData");
             myButton.setFont(new Font("Sansserif", Font.PLAIN, 14));
             myButton.setSize(15, 10);
             myButton.addActionListener(new button());
             add(myButton);
     private class button implements ActionListener {
        public void actionPerformed(ActionEvent e) {
             PostMsg(10,"hello");
     public void PostMsg(int score, String name){
           try {
                  String data = "name=" + name + "score=" + score;          
                  byte[] parameterAsBytes = data.getBytes();   
                // Send data
                   URL url = new URL("http://localhost/addtest.php");
                   URLConnection con = url.openConnection();
                   ((HttpURLConnection) con).setRequestMethod("POST");  
                  con.setDoOutput(true);  
                  con.setDoInput(true);  
                  con.setUseCaches(false);  
                  OutputStream wr = con.getOutputStream();     
                  wr.write(parameterAsBytes);
                   wr.flush();
                   // Get the response
                   BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));
wr.close();
                   rd.close();
               } catch (Exception e) {
                    System.out.println("ERROR"+e.getMessage());
<html>
<title>Untitled Document</title>
</head>
<body>
include("../connectionJAVA/connect.php");
$name = $_POST['name'];
$score =$_POST['score'];
//insert data
$sql = "insert into java
values(null,'$name','$score')";
mysql_query($sql) or die("error=$sql");
</body>
</html>

Maybe you should set the proper header according to your form encoding, should be:
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");And I think this encoding requires a newline after each parameter, "\n" may suffice, may need even carriage return: "\r\n" (or "\n\r" I never remeber for sure).
Anyway why don't you use a simple GET instead, since you're sending just one parameter?
Bye.

Similar Messages

  • Need Help ! how can I Pass Variable from JApplet to PHP?

    I think I post to the wrong forum and I don't know how to change.
    Sorry for messing thing.
    I try to send variable for applet to php but the result is no data was recorded in my database.
    I think the data did not transfer to php.
    I am familiar with php but new to java.
    Actually, I don't know how to send the variable for applet.
    For example, in PHP will receive $_POST['score'] so in applet, I need to send the variable name "score".
    In the book that I use for self-study, mention about servlet but I think PHP is much easier to me.
    So I need to know how set this request data to my applet.
    In internet, I still not get what is clear for me to understand.
    Or I may search with worng keyword or way.....
    Can someone please help me?
    public class test extends JApplet { public test(){ JButton myButton = new JButton("sendData");         myButton.setFont(new Font("Sansserif", Font.PLAIN, 14));         myButton.setSize(15, 10);                 myButton.addActionListener(new button());         add(myButton); } private class button implements ActionListener {         public void actionPerformed(ActionEvent e) {         PostMsg(10,"hello");         } } public void PostMsg(int score, String name){ try {             String data = "name=" + name + "score=" + score;                    byte[] parameterAsBytes = data.getBytes();      // Send data     URL url = new URL("http://localhost/addtest.php");     URLConnection con = url.openConnection();     ((HttpURLConnection) con).setRequestMethod("POST");          con.setDoOutput(true);          con.setDoInput(true);          con.setUseCaches(false);          OutputStream wr = con.getOutputStream();              wr.write(parameterAsBytes);     wr.flush();     // Get the response     BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream())); wr.close();     rd.close(); } catch (Exception e) { System.out.println("ERROR"+e.getMessage()); } } }
    <html> <title>Untitled Document</title> </head> <body> include("../connectionJAVA/connect.php"); $name = $_POST['name']; $score =$_POST['score']; //insert data $sql = "insert into java values(null,'$name','$score')"; mysql_query($sql) or die("error=$sql"); </body> </html>

    rinJava wrote:
    I think I post to the wrong forum and I don't know how to change.Yep wrong forum. This is probably a html/applet/web service sort of question.

  • How can I pass variables from one project to another using Javascript?

    Hi all, I am trying to do this: let learners take one course and finish a quiz. Then based on their quiz scores, they will be sent to other differenct courses.
    However, I wish keep track on their previous quiz scores as well as many other variables.
    I found this nice widge of upload/download variables by CPguru (http://www.cpguru.com/2011/05/18/save-and-load-data-widget-for-adobe-captivate-4-and-adobe -captivate-5/). However, this widget works by storing variables from one project in local computer and then upload it to another project.
    My targeted learners may not always use the same computer though, so using this widget seems not work.
    All these courses resided in a local-made LMS which I don't have access to their code. Therefore, passing variables to PHP html files seems not work.
    Based on my limited programing knowledge, I assume that using Javascript to pass variables may be the only possible way.
    Can someone instruct me how to do this?
    Thank you very much.

    If you create two MIDlet in a midlet suite, it will display as you mentioned means you can't change the display style.

  • How can i pass variables from component MXML to main MXML

    I have been struggling to pass some variables from my custom PanelTest.mxml to Main.mxml
    In my Main.mxml, i tried:
    import PanelTest;
    private var newVar:String;
    private var _panel:PanelTest;
    _panel.thisVar = newVar;
    I then bind the newVar to a Label textfield and nothing happens.
    Thanks

    One possibility would be to use a Login PEI to set a unique UserInfo Name/Value for the user. I think in 5.0 each guest session is unique, so would have unique UserInfo. Then you could pass this value to your portlet (by specifying it in the web service) and use it as a key into a Application-scoped hashmap where you store your info. In other words, your Application variables option, but you have a way of uniquely naming your variables via PEI-set UserInfo.

  • How can I pass parameters from one process flow to another process flow?

    How can I pass parameters from one process flow to another process flow (sub process) in warehouse builder? let me know the steps I have to do in warehouse builder.
    Thanks in advance,
    Kishan

    Hi Kishan,
    Please post this question to the Warehouse Builder forum:
    Warehouse Builder
    Thanks, Mark

  • HT201250 how can i pass information from one mac to another mac by using the time capsule

    how can i pass information from one mac to another mac by using the time capsule

    If you want to transfer files, settings, etc., you must open Migration Assistant (Applications > Utilities) in the Mac that you want to transfer the files and follow the instructions

  • How can I pass parameter from report to form?

    Hi :)
    Now I try to build conference room like this by using form
    and report. And i design that when users click at group report
    then i'll show page that contain questions report and add
    question form. And question form and report must receive the
    same parameter from group report.
    First Problem: is I don't know how group report send the
    same parameter to question report and add question report at the
    same time. And is it possible??? If not please suggest me what
    should I do???
    Second Problem: is I don't know how can I pass parameter from
    report to form. I don't know the way to do it.
    Please tell me!!! Please...
    I look forward to hearing from all of you.
    Thank You.

    One way is to create a link based on that form and attach that
    link with the report. Through links you can pass parameters

  • Passing variables from AS3 to PHP

    Hi there
    I am having some trouble in passing variables from AS3 to PHP. I am using flash and php both in the same file [try.php].
    I've stuck with this for two days.. Here's what I have done. Please help!!!
    header.fla [Actionscript in the timeline]
    stop();
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.net.*;
    var url:String = "http://localhost/0000/try.php";
    var req:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader();
    var variables:URLVariables = new URLVariables();
    send_btn.addEventListener(MouseEvent.CLICK, sendForm);
    function sendForm(evt:MouseEvent):void
        // add the variables to our URLVariables
        variables.asd = "value";
        // send data via post
        req.method = URLRequestMethod.POST;
        req.data = variables;
        loader.dataFormat = URLLoaderDataFormat.TEXT;
        // add listener
        loader.addEventListener(Event.COMPLETE, onLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        //send data
        loader.load(req);
    function onLoaded(evt:Event):void
        var result_data:String = String(loader.data);
        if (result_data)
            trace(result_data);
        else if (!result_data)
            trace("error");
    function ioErrorHandler(event:IOErrorEvent):void
        trace("ioErrorHandler: " + event);
    try.php
    <body>
    <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="563" height="280">
      <param name="movie" value="header.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <param name="swfversion" value="6.0.65.0" />
      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
      <param name="expressinstall" value="../Scripts/expressInstall.swf" />
      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="header.swf" width="563" height="280">
        <!--<![endif]-->
        <param name="quality" value="high" />
        <param name="wmode" value="opaque" />
        <param name="swfversion" value="6.0.65.0" />
        <param name="expressinstall" value="../Scripts/expressInstall.swf" />
        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
        <div>
          <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
          <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
        </div>
        <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
    <?php
    if($_POST['asd'])
    echo "value of var1 is <b>".$_POST['asd']."</b>";
    else
    echo "bad luck";
    ?>
    </body>
    BIG THANKS!!

    the problem is nothing your showed.   did you see a security warning that you ignored?
    to test, if that's the problem go here and adjust your security settings:  http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.ht ml
    if that fails, upload your files to a server and confirm everything works.  then start working on your local configuration.

  • How can I pass value from sql query to unix script

    I am new to oracle/unix.
    I want to write a simple script to find max date from a table and then pass date into a variable in a korn shell script.
    sql is select max(date) from table;
    how can I pass that value in unix shell as a variable. Thanks

    I use to code like this.
    Enjoy Scripting.
    cmd.sql
    select sysdate from dual;
    exit
    db.sh
    #! /usr/bin/ksh
    . ~oracle/.orapaths
    dbdate=$(sqlplus -S user/pwd@servicename @cmd.sql)
    echo $dbdate
    Run shell scripts
    ./db.sh
    SYSDATE --------- 19-JAN-07

  • How can I pass arguments from one MIDlet to another MIDlet

    Hi everybody !
    Can anybody help me in knowing that how can I pass the parameters from one
    MIDlets to another one in same application.
    I am devloping a application in which I am using more than two MIDlet and I
    want to transfer Parameter from one MIDlet to another one.
    I just explain what I have done....
    I made a MIDlet "A" and "B" in the same project using NetBeans IDE.
    In MIDlet "A" I create the Object of MIDlet "B" so that the constructor of
    MIDlet "B" is called and parameter can be transferred.
    But when I run the program it shows me two MIDlet on the screen, that I
    doesn't need.
    Suggestion are most welcome....
    Thanks in advance
    Regards
    Bhagwat

    If you create two MIDlet in a midlet suite, it will display as you mentioned means you can't change the display style.

  • How can I pass data from a form guide to another form in a business process

    How do we pass data from a form guide to another form(not necessarily a guide) without having to open the form. For example we have a small form guide to capture the contract id so we can then get data from contracts table to present to the user in a form. We want the user to open the guide (either Flex guide or form guide) to enter the contract id. Upon submission we want the process to get the contract data and put it into the form that will be opened at the next step by the user without having a user interact with the form to get the data into it. In other words we need the process to get the data and populate a different form than the form guide the contract id was entered in and this new form needs to be opened in the next step by the user.

    Firstly, I'm assuming that you have a Forms ES Server if you are rendering a Guide.  This could be either version ES1, ES2/2.5 or ES3/ADEP
    If you submit the form back to the server, you can populate a second (PDF/XDP) form with the data bound to the same schema/Data Model using Forms ES. 
    You referred to the next user in the chain - If you are using Process Management, this is very easy, as you define what form is used to render the data in the "Presentation & Data" section of the Assign Task activity

  • How can I pass variable's from one frame to other

    //This is the first frame where the value in the TextField
    //tf1 and tf2 are to be passed to 2nd Frame
    import java.awt.*;
    import java.awt.event.*;
    public class del extends Frame implements ItemListener,ActionListener
    public Panel p,p1,p2;
    public Button b,n;
    public Label l1,l2;
    public TextField tf1,tf2;
    public del()
    setLayout(new FlowLayout(FlowLayout.LEFT));
    Panel p=new Panel();
    n=new Button("Submit");
    p.add(n);
    add(p);
    l1=new Label(" Enter the Temperature : ");
    tf1=new TextField(5);
    p.add(l1);
    p.add(tf1);
    add("South",p);
    l2=new Label(" Enter the Compund ");
    tf2=new TextField("N-OCTANE",15);
    p1=new Panel();
    p1.add(l2);
    p1.add(tf2);
    add("South",p1);
    setSize(600,700);
    setVisible(true);
    public void itemStateChanged(ItemEvent ie)
    repaint();
    public void actionPerformed(ActionEvent a)
    if(a.getSource()==n)
    this.setVisible(false);
    new Finalput1();
    repaint();
    public static void main(String[]args)
    del d=new del();
    //2nd Frame which will appear on clicking submit button
    import java.awt.*;
    class del1 extends Frame
    public static double T;//value in 1st text field has to be stored in variable T
    String compd=" ";//value in 2nd textField has to be stored in this string
    TextField tf;
    public del1()
    setLayout(new FlowLayout());
    setSize(800,700);
    setVisible(true);
    public void paint(Graphics g)
    g.drawString(" INPUT DATA : - ",30,120);
    g.setColor(Color.black);
    g.drawString(" Component Name ="+compd,20,160);
    g.drawString(" Temperature of the Mixture ="+T,30,250);
    public static void main(String[]args)
    new del1();
    Pls help me.
    I will be happy if anyone help's me!

    Both your classes seem to be independent applications. (they are public, and they have their public static void main)
    Is this your intention? If so, your question is how to pass data from one application to another. That can be done in many ways, and it is a complicated issue. (if one application wants to pass data to another, you first have to find the other one, and if it isnt running you might want to start... - lots of things to think about.)
    If what you want to do is simply to pass data from one Frame to another, the matter is quite more simple.
    Here is a sample:
    import java.awt.event.*;
    import java.awt.*;
    public class F1 extends Frame implements ActionListener
    private F2 theOtherFrame;
    public F1()
    Button b;
    b=new Button("Action");
    b.addActionListener(this);
    add(b);
    setSize(100,100);
    setVisible(true);
    public void actionPerformed(ActionEvent e)
    if (theOtherFrame == null)
         theOtherFrame = new F2();
         theOtherFrame.setSize(100, 100);
    theOtherFrame.setSomeData("Her you have som data");
    theOtherFrame.setVisible(true);
    public static void main(String[] args)
    new F1();
    class F2 extends Frame
    private String strData;
    private Label lab;
    public void setSomeData(String str)
    lab.setText(str);
    repaint();
    public F2()
    lab = new Label();
    add(lab);

  • How can i pass string from C++ DLL to Java via JNI?

    Hi everybody. I made a DLL with Borland C++. I must pass a string from this dll to Java via JNI.Namely i define a string variable in C++ DLL and i send this variable's value to Java via JNI.
    I can pass integers but i couldnt Strings. . How can i do this? is there any sample?

    Hi,
    So your function should be private static native String get_text();
    (It's often a good idea to make native methods private since when you change signatures you generally have to change java wrapper methods only).
    I know nothing about C++ strings but I'm pretty sure that you can convert it to char*, so
    do :
    char* szMyString = myString.toChar*();
    Then return from native with JNU_NewStringPlatform(env, szMyString)
    (see my 1st answer for JNU_NewStringPlatform() description).
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can I pass information from one portlet to another?

    First, some background...
    I am using Portal 5.0.2 and developing portlets using JSP/Java on a remote server.
    I need to pass information from a portlet on pageA to another portlet on pageB, but I can't do it using the traditional methods, such as query string, session, cookies, etc. due to either portal framework limitations or because of functional constraints (basically, a user will not necessarily be logged in to the portal, but he can view anything available to the GUEST user). Here are the different ways I've considered using to save state and their limitations:
    Query string: can't use this because portlets on remote servers don't have access to it
    Cookies: if user disables cookies, code will not function properly
    Session variables: limited to one user's connection with one portlet (i.e., can't access a session variable set in portletA from portletB)
    Application variables: because the user may not be logged in, I have no way of uniquely naming variables, which is a necessity in order to maintain state for EACH user
    User Settings: again, the user may not be logged in, so I can't use these
    PCC: can't access client-side variables because server-side JSP executes first
    Are my assumptions above correct? Has anyone had any success using one of these methods given the same constraints, or does anyone have an alternative solution? I'd certainly appreciate any help anyone could provide.
    Thanks,
    Jose

    One possibility would be to use a Login PEI to set a unique UserInfo Name/Value for the user. I think in 5.0 each guest session is unique, so would have unique UserInfo. Then you could pass this value to your portlet (by specifying it in the web service) and use it as a key into a Application-scoped hashmap where you store your info. In other words, your Application variables option, but you have a way of uniquely naming your variables via PEI-set UserInfo.

  • How can I pass variable to eventdriven startElement() function?

    I am new to java and SAX. Could anybody tell me how to pass variable to eventdriven startElement function? I tried the following code but didn't work.
    public class ReadXmlSax extends DefaultHandler
    String elementName;
    String requestName;
    Vector v = new Vector();
    public Enumeration getAttribute(String sFileName, String sTagName, String sAttrName)
         Enumeration e;
         elementName=sTagName;
    requestName=sAttrName;
    File f = new File(sFileName);
    // Use an instance of ourselves as the SAX event handler
    DefaultHandler handler = new ReadXmlSax();
    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse(f, handler);
    } catch (Throwable t) {
    t.printStackTrace();
    e = v.elements();
    return(e);
    //===========================================================
    // SAX DocumentHandler methods
    //===========================================================
    public void startDocument()
    throws SAXException
    public void endDocument()
    throws SAXException
    public void startElement(String namespaceURI,
    String sName, // simple name
    String qName, // qualified name
    Attributes attrs)
    throws SAXException
              //System.out.println(elementName);
              if (qName.equals(elementName))
                   String serverName = attrs.getValue("",requestName);
                   v.addElement(serverName);
    }

    I attached the main call the ReadXmlSax class. I added the
    "system.out.println(elementName);" in the function getAttribute and startElement as well. I got printing out "name" for elementName from function getAttribute but got others printing out "null" for elementName from function startElement. Any suggestions? thanks
    import java.io.*;
    import java.util.*;
    import ReadXmlSax;
    public class ReadElement
         public static void main(String argv[])
              ReadXmlSax r = new ReadXmlSax();
              Enumeration e = r.getAttribute("dre.xml","server","name");
              try{
                   while (e.hasMoreElements()) {
                   System.out.println((String)e.nextElement());}
              }catch(Throwable t){
                   t.printStackTrace();
    <strong>test</strong>

Maybe you are looking for

  • When moving picture it copies itself

    Hi, first of all I'm very new to Adobe Flash Pro CS 5 so just getting started with using the program... Unfortunately I've encountered a big problem: In Action Script 3.0 : When I import a picture (JPEG-Format) to the stage and move it around to alig

  • IMP80 and Oracle 8i Lite

    Hello, Does anybody know how to import data from a .dmp file into 8i Lite? I've tried using the imp80 and exp80 tools but I got an error that the import/export views were not installed in the database. Thanks in advance. Brian

  • Auto Text Forwarding to Email?

    Does anyone know a solution either within the phone or using an app, by which I can have text messages automatically forwarded to an email address?  I now work in a location that does not allow cell phones and would like to be able to receive my text

  • Info about Web Services

    Hi Guys,         I am new to webservices. My company wants to implement it for doing few things: 1. we should be able to create a vendor / change vendor information and do the vendor inquiry? I am not sure how to approach this? Can someone guide me a

  • Mail 'reply' indicator shows up even though msg not replied to

    I just upgraded to Lion a few days ago.  I am having new messages show up with the curved reply indicator, even though I have not replied to them.  It seems if I have EVER replied to a particular recipient, (as in a past reply was sent), then the ind