我读了很多关于这个主题的帖子,但我似乎仍然不能弄清楚。
我正在构建一个Mac/PC桌面应用程序。当用户首次授权应用程序时,我想将他们的信息存储在在线Mysql数据库中。我使用JUCE库在线调用和处理php文件,该文件反过来处理在线数据库的更新。在我的桌面应用程序:
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();
和php文件:
<?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;
?>
在我的桌面应用程序上,结果返回"true",但信息实际上并没有保存到数据库中。如果不是
InputStream *input = authURL.createInputStream(true);
我使用:
authURL.launchInDefaultBrowser();
在浏览器中打开PHP文件,一切正常。知道我哪里做错了吗?
Joe,
似乎是你在这个论坛上的第一个问题。如此受人欢迎。你提到你想在在线数据库中存储信息。但是,在连接时,您通过
mysqli('localhost',
。更新localhost,通过查找其ip地址/服务器名、用户名和密码来指向在线数据库。此外,您还必须确保运行此应用程序的计算机可以连接到该在线数据库。
这是我在本地运行并为我工作的。
<?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;
CreateInputStream中的"true"参数告诉它使用POST数据而不是GET,因此调用忽略了GET数据。谢谢你的帮助。