2014-01-12 2 views
0

나는 테이블에 레코드를 만들기위한 .php가 있습니다. 나는 그것이 맞다라고 생각한다. 그러나 나는 그것에서 URL에서 매개 변수를 건네 줄 수 없다. 그리고 그것에 틀린 somethings.URL에 PHP가있는 다중 매개 변수를 전달합니다.

<?php 

/* 
* Following code will create a new product row 
* All product details are read from HTTP Post Request 
*/ 

// array for JSON response 
$response = array(); 

// check for required fields 
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) { 

    $name = $_POST['name']; 
    $price = $_POST['price']; 
    $description = $_POST['description']; 

    // include db connect class 
    require_once __DIR__ . '/db_connect.php'; 

    // connecting to db 
    $db = new DB_CONNECT(); 

    // mysql inserting a new row 
    $result = mysql_query("INSERT INTO products(name, price, description) VALUES('$name', '$price', '$description')"); 

    // check if row inserted or not 
    if ($result) { 
     // successfully inserted into database 
     $response["success"] = 1; 
     $response["message"] = "Product successfully created."; 

     // echoing JSON response 
     echo json_encode($response); 
    } else { 
     // failed to insert row 
     $response["success"] = 0; 
     $response["message"] = "Oops! An error occurred."; 

     // echoing JSON response 
     echo json_encode($response); 
    } 
} else { 
    // required field is missing 
    $response["success"] = 0; 
    $response["message"] = "Required field(s) is missing"; 

    // echoing JSON response 
    echo json_encode($response); 
} 
?> 

는이 같은 URL에 PARAMS을 통과 :

localhost:81/android/create_product.php?name='test'&price='35000'&description='test' 

는 PHP 코드가 잘못 또는 뭔가 다른 무엇입니까? 당신이 URL에 매개 변수를 전달하는 경우 URL의 paramiters에 대한

답변

1

사용 $_GET

if (isset($_GET['name']) && isset($_GET['price']) && isset($_GET['description'])) 
1

당신은 [ '이름']

처럼되지 $ _POST에 의해

$_GET['name'] 

방법으로 그것을 얻을 필요

if (isset($_GET['name']) && isset($_GET['price']) && isset($_GET['description'])) 
관련 문제