This works great:
$username= $_GET["username"]; $query= "INSERT INTO test (latitude) VALUES ('$username')"; mysql_query($query) or die (mysql_error("error")); mysql_close();
This does not work:
if(!isset($_POST['submit'])) { } else { $username= $_GET["username"]; $query= "INSERT INTO test (latitude) VALUES ('$username')"; mysql_query($query) or die (mysql_error("error")); mysql_close(); }
It works if $ username is given by something other than get, for example, '7'.
GET retrieves a value from c. If I did not put it in an if statement, it will just go into my database hundreds of times. If I put it in the if statement, it will only be entered once, but the value will be zero. I am completely at a dead end. Any help would be great.
EDIT: I think because of the answers I get, I didnโt explain very well. clarify: I am using POST to send user_id, answer_body. I use GET to import latitude and longitude from Core Location (although I named this username, this is latitude). I want all of them to be in the same record, so I will associate GET with isset_POST. Also, when the GET (username) is on its own, with an INSERT request, it will do hundreds of duplicates in my database. Here is the objective-C script:
//sends whatever username is set to, to database float username = location.coordinate.latitude; NSString *theValue = [NSString stringWithFormat:@"%f", username]; NSString *hostStr =[NSString stringWithFormat:@"http://mysite.com/page.php?username=%@", theValue]; NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]]; NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSUTF8StringEncoding]; NSLog(@"Server output: %@", serverOutput);
Form Code:
<form action="gpstestertwo.php" method="post"><center> $<input type="text" name="answer_body" maxlentgh= "5" style="height:3em;"/> <input type="submit" value="submit" name="submit" style="height:2em; width:5em; font-size:19px " /> </center> </form>
source share