duanchuan6350 2013-01-17 06:43
浏览 62
已采纳

如何使用Web浏览器检查我的php功能是否正确?

I have just started my HTTPREQUEST application and I am trying to set up my php files first.

I have this insert function on my wamp/www/MenuBook/ folder :

<?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);
}
?>

Now I would like to check if it would insert data into the database using my browser something like this :

localhost/MenuBook/insertOrder.php?$table_ID=003&$MenuBook=01&$order_status=PENDING&$order_date=2013-01-17&$order_receipt=NO

as of now it returns this in the browser:

{"success":0,"message":"Required field(s) is missing"}

Any ideas how I could try and check this?

  • 写回答

4条回答 默认 最新

  • dt102282 2013-01-17 06:49
    关注

    This will not insert data because:

    1. You are passing variables in URL (GET Method) and using them in your script using $_POST.
    2. Also you have not even correctly passed the variables in URL it must be table_ID, MenuBook etc instead of $table_ID,$MenuBook.

    The solution is either user $_GET or $_REQUEST in your script or if possible pass the values using POST method (an better choice).

    For testing: If you have used $_GET or $_REQUEST in your script, simply copy-paste the generated URL into the browser and have a test run. Else if have used POST create a sample form(If you don't have) and submit it to have a test.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名