我刚开始我的HttpRequest应用程序,我想先设置我的PHP文件。如何检查我的PHP函数中使用Web浏览器是正确的?
我有这个插入功能对我wamp/www/MenuBook/
文件夹:
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['table_ID']) && isset($_POST['MenuBook']) && isset($_POST['order_status'])&& isset($_POST['order_date'])&& isset($_POST['order_receipt'])) {
$tableID = $_POST['table_ID'];
$menuBook = $_POST['MenuBook'];
$order_status = $_POST['order_status'];
$order_date = $_POST['order_date'];
$order_receipt = $_POST['order_receipt'];
// inlude db connect class
require_once __DIR__ . '/DBConnect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO orderdb(table_ID,MenuBook,order_status,order_date,order_receipt) VALUES('$table_ID', '$menuBook', '$order_status','$order_date','$order_receipt')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Order 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);
}
?>
现在我想,以检查它是否会用我的浏览器这样的数据插入到数据库:
localhost/MenuBook/insertOrder.php?$table_ID=003&$MenuBook=01&$order_status=PENDING&$order_date=2013-01-17&$order_receipt=NO
截至目前它在浏览器中返回这个:
{"success":0,"message":"Required field(s) is missing"}
任何想法如何,我可以尝试,并检查呢?
返回相同的消息没有$符号。我使用的网址有问题吗? –
见上面的Ravi's anser;你已经在你的代码中使用了$ _POST,当你的变量使用$ _GET传递时 - 所以变量永远不会被脚本拾取。 – ChidG
但是请注意,由于Ravi说POST是一个更好的选择(特别是如果您使用表单传递数据),但是如果您没有这样做,您需要构建一个表单来测试它。 – ChidG