試圖填充一個MySQL數據庫,但如果我有郵差或Android工作室發送變量我得到這個PHP代碼沒有乳寧
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
</head>
<body>404 Not Found</body>
</html>
,這是我的PHP代碼,我leftout安全數據庫的用戶名和這樣的但我向你保證,他們是正確的
<?php
/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*ordernum,pilotname,pilotcash,date,planemodel,hoobsstart,hoobsend,watchtime,hoobstime ,gas ,liter ,repairname ,repaircost ,travelexpense,othername1,othercost1
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['pilotname']) && isset($_POST['pilotcash']) && isset($_POST['date']) && isset($_POST['planemodel'])&& isset($_POST['hoobsstart'])&& isset($_POST['hoobsend'])&& isset($_POST['watchtime'])&& isset($_POST['hoobstime'])&& isset($_POST['gas'])&& isset($_POST['liter'])&& isset($_POST['repairname'])&& isset($_POST['repaircost'])&& isset($_POST['travelexpense'])&& isset($_POST['othername1'])&& isset($_POST['othercost1'])) {
$pilotname = $_POST['pilotname'];
$pilotcash = $_POST['pilotcash'];
$date = $_POST['date'];
$planemodel = $_POST['planemodel'];
$hoobsstart = $_POST['hoobsstart'];
$hoobsend = $_POST['hoobsend'];
$watchtime = $_POST['watchtime'];
$hoobstime = $_POST['hoobstime'];
$gas = $_POST['gas'];
$liter = $_POST['liter'];
$repairname = $_POST['repairname'];
$repaircost = $_POST['repaircost'];
$travelexpense = $_POST['travelexpense'];
$othername1 = $_POST['othername1'];
$othercost1 = $_POST['othercost1'];
define('DB_USER', "`enter code here`"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', ""); // database name
define('DB_SERVER', ""); // db server
// array for JSON response
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE);
$sql = "INSERT INTO orden(pilotname,pilotcash,date,planemodel,hoobsstart,hoobsend,watchtime,hoobstime,gas,liter,repairname,repaircost,travelexpense,othername1,othercost1) VALUES('$pilotname','$pilotcash','$date','$planemodel','$hoobsstart','$hoobsend','$watchtime','$hoobstime','$gas','$liter','$repairname','$repaircost','$travelexpense','$othername1','$othercost1')";
// mysql inserting a new row
$result = $conn->query($sql) or die (mysqli_connect_error());
// 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方法。你提到你的問題。順便說一句,如果你的代碼仍然如此,你的數據庫很容易被sql注入。 –
這是一個錯字,即時通訊使用郵遞員或android studio發送它需要運行的變量,但我沒有迴應,我應該得到$ response [「success」] = 1; $ response [「message」] =「產品成功創建。」;或$ response [「success」] = 0; $ response [「message」] =「必填字段丟失」;或$ response [「success」] = 0; $ response [「message」] =「糟糕!發生錯誤。」;相反,我得到<!DOCTYPE HTML>