从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

前端之家收集整理的这篇文章主要介绍了从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码
NSDate *workingTill = timePicker.date;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSString *time = [formatter stringFromDate:workingTill];

NSString *post = [NSString stringWithFormat:@"shift=%@&username=%@",time,usernameString];

NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d",[post length]];

NSURL *url = [NSURL URLWithString:@"http://wowow.PHP"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
NSLog(@"%@",post);
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

[NSURLConnection connectionWithRequest:request delegate:nil];

[self.navigationController popToRootViewControllerAnimated:YES];

这里是PHP的一大块,POST变量不在正确的位置?

<?PHP
function objectsIntoArray($arrObjData,$arrSkipIndices = array())
{
    $arrData = array();

    // if input is object,convert into array
    if (is_object($arrObjData)) {
        $arrObjData = get_object_vars($arrObjData);
    }

    if (is_array($arrObjData)) {
        foreach ($arrObjData as $index => $value) {
            if (is_object($value) || is_array($value)) {
                $value = objectsIntoArray($value,$arrSkipIndices); // recursive call
            }
            if (in_array($index,$arrSkipIndices)) {
                continue;
            }
            $arrData[$index] = $value;
        }
    }
    return $arrData;
}

    $newShift = $_POST('shift');
    $bartenderUsername = $_POST('username');

    MysqL_connect("host","name","pw") or die(MysqL_error());  
    MysqL_select_db("harring4") or die(MysqL_error());

    $result = MysqL_query("SELECT * FROM BartenderTable WHERE username='".$bartenderUsername."'") or die(MysqL_error());  

    $row = MysqL_fetch_array($result);
    $newfname = $row['fname'];

我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!

解决方法

$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:
$newShift = $_POST['shift'];
$bartenderUsername = $_POST['username'];
原文链接:https://www.f2er.com/iOS/329053.html

猜你在找的iOS相关文章