우리는 PHP를 사용하여 WAMP 서버에 액세스하는 하나의 안드로이드 응용 프로그램을 보유하고 있습니다. Select * 등의 모든 쿼리는 정상적으로 작동합니다. 그러나 특정 조건에서 제대로 작동하지 않는 쿼리 삽입 WAMP에 이미 데이터베이스에 데이터가 있으면 데이터베이스에 새 데이터를 삽입하지 못했습니다. 그러나 WAMP 서버에 기존 데이터가 없으면 쿼리 작업을 성공적으로 삽입하십시오. 다음 PHP 코드는 우리가삽입 쿼리가 WAMP 서버에서 작동하지 않습니다.
<?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['UserName']) && isset($_POST['UserID']) && isset($_POST['Password']) && isset($_POST['Age'])&& isset($_POST['ContactNumber']) && isset($_POST['expiryDate'])) {
$UserName = $_POST['UserName'];
$UserID = $_POST['UserID'];
$Password = $_POST['Password'];
$Age = $_POST['Age'];
$ContactNumber = $_POST['ContactNumber'];
$expiryDate = $_POST['expiryDate'];
// 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 normaluser(UserName, UserID, Password,Age,ContactNumber,expiryDate) VALUES('$UserName', '$UserID', '$Password','$Age','$ContactNumber','$expiryDate')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "New user successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! error is there.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required fields is missing";
// echoing JSON response
echo json_encode($response);
}
?>
너희들은 해결이 문제에 대한 사용을 도와주세요 수, 데이터를 삽입하기 위해 사용하고 있습니까?
당신은 오류 검사를하지 않는다 : 당신은 아마 사용자에게 다시 전송 이러한 오류를 싶지 않는 있지만 정확한 오류는 MySQL의에서 반환되는 당신을 말할 것이다 이것은 조금 단순하다. 오류가 무엇인지 보려면'mysql_error()'를 사용하십시오. –
mysql_real_escape_string()을 사용하여 입력 값을 살균하는 것이 좋습니다. 그렇지 않으면 SQL 인젝션이 가능합니다. – frank1fr
[누군가가 'SQL Injection'이라고 했습니까?] (http://xkcd.com/327/) – MisterBla