无法将数据库连接到HTML表单

时间:2015-07-17 04:59:13

标签: php html database

我在html中构建了一个表单,但是我无法将表单中的数据连接到数据库。这是我用来连接和收集表单数据的代码。

HTML表单 - > https://drive.google.com/file/d/0B4eL9qVqrm2OOWpMZmV1dUlNbTg/view?usp=sharing

PHP连接文件 - > https://drive.google.com/file/d/0B4eL9qVqrm2OY2pDR09nb0w5bE0/view

PHP数据库文件 - > https://drive.google.com/file/d/0B4eL9qVqrm2OeU5IdVMxVHBkaVk/view

它会在单击提交时返回代码。

@implementation VCConnectionManager

+(instancetype) sharedInstance {
 DEFINE_SINGLETON_WITH_BLOCK(^{
 return [[VCConnectionManager alloc] init];
});
}

 - (void) actionmethod:(NSString *)action parameters:(NSDictionary *)param  onComplete:(void (^)(NSMutableDictionary *json))successBlock onError:(void (^)(NSError *error))errorBlock {

 BOOL network = [self currentNetworkStatus];
 if(network){

        NSString     *weburl = WS_BASE_URL;
        NSString * completeRequestUrl = [NSString stringWithFormat:@"%@%@", weburl,action];
        DDLogVerbose(@"Complete_URL--->%@",completeRequestUrl);
        AFHTTPRequestOperationManager *manager =  [AFHTTPRequestOperationManager manager];
        AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];

        [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        manager.requestSerializer = requestSerializer;
        [params setValue:@"0" forKey:@"loginType"];

       [manager POST:completeRequestUrl parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject){
      successBlock(responseObject);
       DDLogVerbose(@"\n\n\n\nResponse Result---->%@",responseObject);
  }
  failure: ^(AFHTTPRequestOperation *operation, NSError *error){
      //DDLogVerbose(@"Error: %@", error);
      errorBlock(error);
  }];
 }
 else{
    UIAlertView *internetAlert = [[UIAlertView alloc]initWithTitle:AppName message:NETWORK_ERROR delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [internetAlert show];
 }
 }

我不知道将数据收集到数据库中并使用在线教程中的php代码。代码仍然没有运行。任何帮助或推动正确的方向将是非常有帮助的。

2 个答案:

答案 0 :(得分:0)

发现两个错误
错误1 - 将表单方法更改为发布,因为php代码使用$ _POST
错误2

mysqli_query($connect"INSERT INTO Visitors(Your_Name,Your_Email_ID,Message,sex)
                VALUES('$Your_name','$email','$Message','$Gender')");

函数参数未用逗号分隔,因此将其更改为

mysqli_query($connect,"INSERT INTO Visitors(Your_Name,Your_Email_ID,Message,sex)
                VALUES('$Your_name','$email','$Message','$Gender')");

答案 1 :(得分:0)

嗯,问题不在于代码,而在于我使用的url路径。我只需要更改localhost / filename.php或localhost / site.html的路径,以便它实际托管并在localhost服务器上运行。您也可以使用绝对服务器而不是localhost。 (并确保所有文件都在mysql的xampp目录下的HTACCESS文件夹中)