Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

first time question. Anyways, I have a bit of a project, basically it has me writing up a GUI using Netbean's GUI builder to get information from a customer and then sending that information into a PHP script. I know that I can get the string from jTextField1.gettext(); and thats well and all, but the problem comes with sending that specific information to the PHP script that will send it to the mySQL database in the group's website.

Java coding for a method that should theoretically work when it's called in the submit action method:

public void Dsend() throws Exception {
URL hp = new URL("http://www.luxuryparking.comeze.com/DBinput.php"); 
HttpURLConnection hpCon = (HttpURLConnection) hp.openConnection();
hpCon.setRequestMethod("POST");
hpCon.setDoOutput(true);
hpCon.setDoInput(true);

        // important: get output stream before input stream
PrintStream ps = new PrintStream(hpCon.getOutputStream());
ps.print(jTextField7.getText());
     ps.print("secondKey=secondValue;");

// we have to get the input stream in order to actually send the request
hpCon.getInputStream();

// close the print stream
ps.close();   
}

PHP Script:

$conn = new PDO("mysql:host=$host;dbname=a4335408_data1", $username, $password);

foreach ($_POST as $key => $value) {
switch ($key) {
    case 'license':
        $license = $value;
        break;
    default:
        break;
}
}

$license='1234567';

$sql = "INSERT INTO Reservation (LicensePlate) VALUES (:license)";

$q = $conn->prepare($sql);

$q->execute(array(':license'=>$license));

Thank you for the help!

share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.