Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从手机应用程序将PHP数据发布到MYSQL服务器_Php_Mysql - Fatal编程技术网

从手机应用程序将PHP数据发布到MYSQL服务器

从手机应用程序将PHP数据发布到MYSQL服务器,php,mysql,Php,Mysql,嗨,我期待着从Android应用程序接收POST数据,并使用PHP脚本将其放入MYSQL服务器 我没有得到任何结果,我已经通过了各种例子和教程 新的工作PHP脚本 <?php $needsarray = str_split('$_POST[needs]'); $needs1 = 0; $needs2 = 0; $needs3 = 0; $needs4 = 0; if ($needsarray[0] =="1"){ $needs1 = 1; } if ($needsarray[1] ==

嗨,我期待着从Android应用程序接收POST数据,并使用PHP脚本将其放入MYSQL服务器

我没有得到任何结果,我已经通过了各种例子和教程

新的工作PHP脚本

<?php
$needsarray = str_split('$_POST[needs]');
$needs1 = 0;
$needs2 = 0;
$needs3 = 0;
$needs4 = 0;

if ($needsarray[0] =="1"){
 $needs1 = 1;
}
if ($needsarray[1] =="1"){
 $needs2 = 1;
}
if ($needsarray[2] =="1"){
 $needs3 = 1;
}
if ($needsarray[3] =="1"){
 $needs4 = 1;
}

$con = mysql_connect("localhost","haitidis_test","S3an");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

 mysql_select_db("haitidis_AppData", $con);

$sql="INSERT INTO Extensive (disaster, people, lat, lng, phone, needs1, needs2, needs3,    needs4) 
VALUES ('$_POST[disaster]', '$_POST[people]', '$_POST[latitude]', '$_POST[longtitude]',     '$_POST[userphone]', $needs1, $needs2, $needs3, $needs4)";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con);
?>

您的代码没有什么问题。我在eclipse中测试了Java代码,PHP看起来不错。对于初学者来说,试着看看你的手机代码和php代码是否真的能相互交流

在PHP末尾添加一个
var\u转储($\u POST)

将代码稍微更改为:

 ResponseHandler<String> responseHandler = new BasicResponseHandler();
 String response = httpclient.execute(httppost, responseHandler);

 System.out.println(response);
如果结果为false,则会转储sql错误:

var_dump(mysql_error());
更新:

警告:mysql\u query()[function.mysql query]:用户访问被拒绝 中的'haitis'@'localhost'(使用密码:否) /home/haitidis/public_html/extensive.php,第42行

您确定使用了正确的密码--“S3an”吗

更新:

在关闭连接之前,您应该输入以下代码行:

$result = mysql_query("INSERT INTO Extensive (disaster, people, lat, lng, phone, 
     needs1, needs2, needs3, needs4) VALUES ($disaster, $people, $lat, $long, $phone,     
    $needs1, $needs2, $needs3, $needs4)");

mysql_close($con);

如果正在插入行,请立即检查数据库。

我的代码中没有一个看起来有任何错误。我导航到php脚本所在的页面,那里什么都没有。我在eclipse中也没有得到任何错误。我的mysql数据库中也没有任何内容。我还使用相同的数据创建了自己的html表单,并尝试将其再次发布到php脚本中,但仍然一无所获……我希望我有一些错误,至少它会给我一些可以使用的东西,请尝试打印response.getStatusLine();从您的表单进行测试,并尝试回显PHPIm页面中的某些内容,现在尝试进行回显,如果遇到一些问题,将在asapI使用我制作的html测试表单时发布结果,我单击了提交,并获得了post值,因此我认为这是一个好迹象,但是当我查看我的sql数据库时,它没有显示添加的行!我尝试获取ddms输出,但没有列出任何内容,因此不确定发生了什么。感谢您提供的调试帮助,这是处理mysql错误的一个好主意。我将继续尝试,我在我原来的帖子中发布了错误。非常感谢。是的,事实上,我把$result=mysql_查询('put INSERT STATEMENT HERE');在我关闭mysql连接之后。我已将其上移,不再接收错误。我已经在我的问题中更新了上面的输出,非常感谢您的帮助,它现在正在工作!我已经在上面的回答中发布了更新的脚本,再次感谢!
$result = mysql_query("INSERT INTO Extensive (disaster, people, lat, lng, phone, 
     needs1, needs2, needs3, needs4) VALUES ($disaster, $people, $lat, $long, $phone,     
    $needs1, $needs2, $needs3, $needs4)");

mysql_close($con);