Wednesday, 20 February 2013


HI THIS TOUTORIAL WILL HELP FULL FOR STARTUP IN IOS CREATED BY NAVEENRAJU

DataBase Insertion























code For Above Demo:



  ViewController.h



//
//  ViewController.h
//  InsertMysql_Registration
//
//  Created by apple on 19/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *t1;
@property (strong, nonatomic) IBOutlet UITextField *t2;
@property (strong, nonatomic) IBOutlet UITextField *t3;
- (IBAction)Register:(id)sender;

- (IBAction)delete:(id)sender;


@end


 ViewController.m


//
//  ViewController.m
//  InsertMysql_Registration
//
//  Created by apple on 19/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController



@synthesize t1;
@synthesize t2;
@synthesize t3;

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    
    
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)Register:(id)sender {
    
    
    NSString *url=[NSString stringWithFormat:@"http://localhost/App1/Registration.php?name=%@&age=%@&sex=%@",t1.text,t2.text,t3.text];
    
    //To exicute php code
    
    NSData *dataUrl=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    
    

    
}

- (IBAction)delete:(id)sender {
    
    NSString *url1=[NSString stringWithFormat:@"http://localhost/App1/Delete.php"];
    
    //To exicute php code
    
    NSData *dataUrl1=[NSData dataWithContentsOfURL:[NSURL URLWithString:url1]];
    
    

    
    
}
@end














 ViewController.xib




Registration.php



<?php

//create data base connections
$user='root';
$pswd='';
$db='iosproj';

$conn=mysql_connect('localhost',$user,$pswd);
mysql_select_db($db,$conn);

//if name,age,sex are seted then only values are inserted
if (isset($_GET['name']) && isset($_GET['age']) && isset($_GET['sex']))
{

$name=$_GET['name'];
$age=$_GET['age'];
$sex=$_GET['sex'];


$result=mysql_query("insert into Register(name
,age,sex)values('$name','$age','$sex')");
}


?>


Delete.php


<?php

//create data base connections
$user='root';
$pswd='';
$db='iosproj';


$conn=mysql_connect('localhost',$user,$pswd);
mysql_select_db($db,$conn);



$result=mysql_query("delete from Register");



?>







PHPMYADMIN:









No comments:

Post a Comment