Hi everybody..
I am a total newbie to iphone development, and i wanna do an application on a test project on remote database server communication.
I know a little bit of iphone sdk and cocoa framework.
My application will contain :
A view with two textfields, one button and one for displaying data.
On launch of the application i want to show
two textfields which will ask the user to enter the userID and password.
The button name will be send and on click of the button, data will be send to the database server and again fetch data from the server and display in the display area.
It will be a simple urlconnection...
I want a simple example code to start up ..
Can anybody help me..plz...
I would suggest having a basic php on your server that takes userID and password as variables, and just echoes the data you want, then in the iphone code, you can do
Hi Robotwoods,
Thanks for ur response..
yeah i can start with , can u tell me how can i get the data back from the sever..
I mean i just want to know that how the data is coming to the variable "data"
plz can u just resolve my query..
thanks..
Edit:
But how will i distinguish between the data, i.e, username & password..
Last edited by fodderkonoko; 03-22-2010 at 11:44 PM.
Well, the first line there says "here is a file" (the file in the example is a php file, that's accepting the variables of 'userID', and 'password' with the values from the UITextFields you said you wanted to have.
The second line says 'data' is what is in the file.
The third line converts 'data' to a string.
The last takes your UITextField and populates it with the string.
Going back to the php file, that was just a proposal...do you have any idea what you [are doing/want to do] at the server? Is it a PHP/MySQL situation? Since you are the only one that knows what your system does, you are the only one that can answer.
When you tell it username and password, what are you expecting it to tell you?
Last edited by RobotWoods; 03-23-2010 at 10:17 PM.
i have a php/mysql connection.
The database will have a table with two columns respectively.
Now in the front end i will have the textarea and two textfields and a button.
Once i write in the textfields and press the button, the strings needs to be sent to the database, through the url as u said, i suppose, and also at the same time fetch the data from the database and put it in the textarea.
but my question is: how will i send the response back from the php/mysql
for the http response.
i mean how will the server side response to my query?
is there any particular strategy i need to follow?
i need to keep it simple for a demo today..
So can u plz give me a short overview on this..
plz..Thanks and many thanks..
anybody!!!
i am really stuck here..
i have not enough knowledge in php/mysql.
and also i dont know enough on iphone api functions related to remote server access.
please guys help me..
Thanks....
Sorry, the time change worked against you. If you look at the URL I proposed, the variables are tacked onto the end (after the .php) and then they take their values from the textfields you mentioned.
Within the php file, you'll need to do whatever you want, so maybe it will be something like (and this is being written on the fly, little security/hashing in mind and no error check)
PHP Code:
<?php
//info.php has your db, server, usr, and pwd variables
require("info.php");
$con=mysql_connect($server,$usr,$pwd);
$db=mysql_select_db($db,$con);
$user=mysql_real_escape_string($_GET["userID"]);
$password=mysql_real_escape_string($_GET["password"]);
//assuming there is a table called users in your db
$checkPwdQuery=mysql_query("SELECT password FROM users WHERE user='$user'");
$storedPwd=mysql_fetch_row($checkPwdQuery);
if ($password==$storedPwd[0]){
die ('Password match');}
else{
die ('Wrong password');}
?>
Thanks for the response..
But i am facing an error in this line :
NSURL *myURL = [NSURL URLWithString:@"http://www.yourserver.com/file.php?userID=%@&password=%@", userIDField.text, passwordField.text];
great example, have been learning php for a bit, and already have a couple apps in the app store...
my question is this. I am trying to do a basic if statement to confirm login, based off the string (Str) but the code does not seem to be working, it always says Login Incorrect, and I know the login is correct, as before this code I have a NSLog displaying Str, and I also have it in a UILabel so I can test with the correct login info and wrong login info