上传到mysql服务器无法正常工作 [英] upload to mysql server not working

查看:116
本文介绍了上传到mysql服务器无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据添加到我的mysql数据库中。但是下面的实际数据库中没有添加任何内容的是我的xcode,下面是我的php代码。似乎无法理解为什么它不起作用?任何建议/你能看到错误吗?

I need to add data to my mysql database.However nothing is being added to the actual database below is my xcode and below that is my php code. Can't seem to see why it doesn't work? Any suggestions / can you see the error?

-(void) postMessage:(NSString*) teamid withPlayerid:(NSString *) playerid withFixtureid:(NSString *) fixtureid withEventid:(NSString *) eventid withHalfid:(NSString *) halfid{

//check isnt receiving two anit paramters
if(teamid !=nil && playerid !=nil && fixtureid !=nil && eventid !=nil && halfid !=nil){

    NSMutableString *postString = [NSMutableString stringWithString:kPostURL];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kTeamid, teamid]];
    //makes kname equal to name
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kPlayerid , playerid]];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kFixtureid, fixtureid]];
    //makes kname equal to name
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kEventid , eventid]];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kHalfid, halfid]];
    //makes kname equal to name

    [postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
    [request setHTTPMethod:@"POST"];

    postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
    NSLog(@"%@",teamid);
    NSLog(@"%@",KTeamid);


}
}

-(IBAction)prop1Button:(id)sender{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"1 - Prop"];

 _textField3.text = myString;
[self postMessage: self.textField2.text withPlayerid:self.textField3.text withFixtureid:self.textField3.text withEventid:self.textField3.text withHalfid:self.textField3.text];
_textField2.text = nil;
_textField3.text = nil;
dropGoalCounter ++;
[[NSNotificationCenter defaultCenter] postNotificationName:@"DoUpdateLabel" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:nil];


}

这是我输入的php代码数据库

Here is my php code for inserting into the database

<?php
include ("./inc/connect.inc.php");
$teamid = (int)$_POST["teamid"];
$playerid = (int)$_POST["playerid"];
$fixtureid = (int)$_POST["fixtureid"];
$eventid = (int)$_POST["eventid"];
$half = $_POST["halfid"];

$query = "INSERT INTO MatchEvent (MatchEventID, TeamID, PlayerID,FixtureID,EventID,Half) VALUES ('','9','1','8','7','$half')";

mysql_query($query) or die(mysql_error("error"));

mysql_close();

?>

编辑!!!
现在这会在数据库中输入一个新条目,但由于NSString,所有字段都是空白的,而在数据库中,列是整数。然而,当我将PHP更改为此

EDIT!!! This now enters a new entry into the database but all the fields are blank im assuming because of the NSString and in the database the columns are integers. yet when i change the php to this

$teamid = (int)$_POST["teamid"]
$playerid = (int)$_POST["playerid"];
$fixtureid = (int)$_POST["fixtureid"];
$eventid = (int)$_POST["eventid"];
$half = (int)$_POST["halfid"];

它根本不会向数据库添加条目。有什么建议?

It doesnt add an entry to the database at all. Any suggestions?

推荐答案

发现问题:

xCode:

[request setHTTPMethod:@"POST"];
                         ^^^^^

PHP:

$teamid = $_GET["teamid"];
            ^^^----hmmmmm. not $_POST

除此之外,你很容易受到 SQL注入攻击

on top of this, you are vulnerable to SQL injection attacks

这篇关于上传到mysql服务器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆