2013-11-02 2 views
-3

프로그래밍을 공부하고 있습니다. 내 XAMPP에서 PHP 파일이 있는데이 파일은 내 데이터베이스에 데이터를 삽입하는 데 사용됩니다.POST 방법으로 웹 서비스를 호출하는 방법

post 메서드를 사용하여 PHP 파일을 호출하고 sql 문자열을 실행하고 싶습니다.

내 PHP 파일 : 당신은 컬을 사용하지 않으려면

<?php 
$DB_HostName = "localhost"; // ten host 
$DB_Name = "QM_TEST";   
$DB_User = "root";   
$DB_Pass = "";    
$DB_Table = "Customer";    

$name = $_GET[@"name"]; 
$address = $_GET[@"address"]; 

$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
mysql_select_db($DB_Name,$con) or die(mysql_error()); 
$sql = "insert into $DB_Table (name, address) values('$name','$address');"; 
$res = mysql_query($sql,$con) or die(mysql_error()); 

mysql_close($con); 
if ($res) { 
    echo "success"; 
}else{ 
    echo "faild"; 
}// end else 
?> 
+1

OSX 또는 Cocoa와 어떤 관련이 있습니까? – dbf

+0

OSx와 관련이 없으며 현재 문제가 무엇인지 명확하지 않습니다. –

답변

0

당신은 [stream_context_create()][1] 함께 할 수 있습니다.

다음은 예입니다 :

$url = 'http://server.com/path'; 
$data = array('key1' => 'value1', 'key2' => 'value2'); 

// use key 'http' even if you send the request to https://... 
$options = array(
    'http' => array(
     'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
     'method' => 'POST', 
     'content' => http_build_query($data), 
    ), 
); 
$context = stream_context_create($options); 
$result = file_get_contents($url, false, $context); 

var_dump($result); 

비슷한 질문 here있다.

+0

죄송합니다! 나는 Xcode에서 코드하고 싶다. ( – user2948373

관련 문제