Question

I've read a lot of posts on this general subject but I still can't seem to figure it out.

I'm building a Mac/PC desktop application. When a user first authorizes the app, I want to store their info in an online Mysql database. I'm using the JUCE library to call and handle a php file online which in turn handles the updating of the online database. On my desktop app:

String url = "http://www.syntorial.com/onlinePHPFileToCall.php?email=" + email + "&computer=" + SystemStats::getComputerName();
URL authURL(url);
InputStream *input = authURL.createInputStream(true);
String result = input->readString();

And the php file:

<?php

$result = "";

$mysqli = new mysqli('localhost','username','password','dbname');

if (mysqli_connect_errno())
{
    $result = "connection failed";
}
else
{
    $mysqli->select_db("UserInfo");

    $email = $_GET['email'];
    $computer = $_GET['computer'];

    $query = "UPDATE UserInfo SET computer = '$computer' WHERE email = '$email'";

    if ($queryResult = $mysqli->query($query))
    {
        $result = "true";
    }
    else
    {
        $result = "false";
    }
}

echo $result;
?>

The result comes back "true" on my desktop app, but the information doesn't actually get saved into the database. If instead of

InputStream *input = authURL.createInputStream(true);

I use:

authURL.launchInDefaultBrowser();

it opens up the php file in a browser and everything works fine. Any ideas what I'm doing wrong?

Was it helpful?

Solution 2

Turns out the "true" argument in CreateInputStream was telling it to use POST data instead of GET so the call was ignoring the GET data. Thanks the help.

OTHER TIPS

Joe,
Seems like one of your first question on this forum. So Welcome. You mentioned you want to store information in an online database. But while connecting you added db information about your local via

mysqli('localhost',

. Update localhost to point to an online database by finding its ip address/servername, username and password. Also you will have to ensure the computer where you run this application can connect to that online db.

Here is what I am ran on my local and worked for me.

<?php

$result = "";

$mysqli = new mysqli('localhost','root','','test');

if (mysqli_connect_errno())
{
    $result = "connection failed";
}
else
{

    $email = "xyz@yahoo.com";
    $computer = "1mycomp";

    $query = "UPDATE so1 SET computer = '$computer' WHERE email = '$email'";

    /* 
      Printing the query to check what is being executed. 
      Remove the below line after program works.
    */
    echo $query;

    if ($queryResult = $mysqli->query($query))
    {
        $result = "true";
    }
    else
    {
        $result = "false";
    }
}

echo $result;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top