안녕하세요 저는이 튜토리얼을 따르고 있습니다 http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ 저는 행을 만들려고 노력하고 있지만 (파트 6) 항상 저는 "필수 필드가 없습니다"메시지가 나타납니다.
코드 다운로드를 시도했지만 운이 없습니다.
내가 뭘 잘못하고 있는지 지시에 따라 phpmyadmin에서 올바른 데이터베이스를 만들었습니다.
<?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);
}
이름, 가격 및 설명을 POST를 통해 제출해야합니다.
이 코드로 html 파일을 만들고 데이터를 입력하면 작동합니다.
<form action="create_product.php" method="post" name="submit_data">
Name: <input type="text" name="name" value="" /><br />
Price: <input type="text" name="price" value="" /><br />
Description: <input type="text" name="description" value="" />
</form>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다