我发送数据从iphone到服务器使用PHP它是从iPhone发送数据,但不插入在MySQL中我使用下面的PHP代码。插入数据在MySQL数据库在PHP
<?php
$con =
mysql_connect("surveyipad.db.6420177.hostedresource.com","tom","ben");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("surveyipad", $con);
$device_Id=$_POST['device_Id'];
$R1=$_POST['R1'];
$R2=$_POST['R2'];
$R3=$_POST['R3'];
$comment=$_POST['comment'];
$update_date_time=$_POST['update_date_time'];
$query=("INSERT INTO survey_responsese_pfizer (device_Id,R1,R2,R3,comment,update_date_time)
VALUES ('$device_Id','$R1','$R2','$R3','$comment','$update_date_time')");
mysql_query($query,$con);
printf("Records inserted: %d\n", mysql_affected_rows());
echo($device_Id)
?>
你做了什么调试? Wheres'echo($ device_Id)'的结尾分号?你也有SQL注入,你应该转义输入否则添加'''你的参数之一将打破查询... –
尝试打印出'mysql_error()',看看是否有某种错误,并张贴它这里 – Darvex
保持您的字符串在引号之外。例如,使用'sprintf'。另外,请注意用户输入,这可能是错误的。在你的'$ _POST'值上需要'Mysql_real_escape_string',正如@zan所说的 - 去看看PDO。旁注:使用'die()'是这里不需要的东西,使用propper错误处理代替 – Tikkes