PHP - include a php file and also send query parameters

后端 未结 13 1144
长发绾君心
长发绾君心 2020-11-27 03:46

I have to show a page from my php script based on certain conditions. I have an if condition and am doing an \"include\" if the condition is satisfied.

if(co         


        
相关标签:
13条回答
  • 2020-11-27 04:50

    Do this:

    NSString *lname = [NSString stringWithFormat:@"var=%@",tname.text];
    NSString *lpassword = [NSString stringWithFormat:@"var=%@",tpassword.text];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://localhost/Merge/AddClient.php"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"insert" forHTTPHeaderField:@"METHOD"];
    
    NSString *postString = [NSString stringWithFormat:@"name=%@&password=%@",lname,lpassword];
    NSString *clearpost = [postString stringByReplacingOccurrencesOfString:@"var=" withString:@""];
    NSLog(@"%@",clearpost);
    [request setHTTPBody:[clearpost dataUsingEncoding:NSUTF8StringEncoding]];
    [request setValue:clearpost forHTTPHeaderField:@"Content-Length"];
    [NSURLConnection connectionWithRequest:request delegate:self];
    NSLog(@"%@",request);
    

    And add to your insert.php file:

    $name = $_POST['name'];
    $password = $_POST['password'];
    
    $con = mysql_connect('localhost','root','password');
    $db = mysql_select_db('sample',$con);
    
    
    $sql = "INSERT INTO authenticate(name,password) VALUES('$name','$password')";
    
    $res = mysql_query($sql,$con) or die(mysql_error());
    
    if ($res) {
        echo "success" ;
    } else {
        echo "faild";
    }
    
    0 讨论(0)
提交回复
热议问题