簡體   English   中英

我正在使用php,json服務,而我在執行以下代碼時卻得到了空白頁,數據庫中未更新任何數據……如果出錯,請更正我

[英]Am using php, json services while i execute below code i am getting a blank page, no data updated in database…correct me if wrong

PHP

我是Web服務的初學者。這是我的代碼在寧靜的Web服務中使用php,json和mysql來更新用戶狀態。即使我無法將用戶信息更新到數據庫.plz也會幫助我。 .. !!

    <?php

    //content header-type

    //header('content-type: application/json');

    // connect to data-base

    $dbhost = 'localhost';
     $dbuser = 'root';
      $dbpass = '';
       $conn = mysql_connect($dbhost, $dbuser, $dbpass); 
       if(! $conn ) 
        {
           die('Could not connect: ' . mysql_error());
            }  

            //on submit action

            if(isset($_PUT['update']))
            {

    if($_SERVER['REQUEST_METHOD'] == "POST")
    {
        $id = isset($_SERVER['HTTP_ID']) ? 
        mysql_real_escape_string($_SERVER['HTTP_ID']) : "";

        $status = isset($_SERVER['HTTP_STATUS']) ? 
        mysql_real_escape_string($_SERVER['HTTP_STATUS']) : "";

        // validations of code

        if(!empty($id)){
            $qur = mysql_query("UPDATE  `miisky`.`register` SET  `status` =  '$status' WHERE  `register`.`ID` ='$id';");
            if($qur){
                $json = array("status" => 1, "msg" => "Status updated!!.");
            }else{
                $json = array("status" => 0, "msg" => "Error updating status");
            }
        }else{
            $json = array("status" => 0, "msg" => "User ID not define");
        }
    }else{
            $json = array("status" => 0, "msg" => "User ID not define");
        }
        @mysql_close($conn);

        /* Output header */
        header('Content-type: application/json');
        echo json_encode($json);
    }
    ?>

HTML

並且聽到我的html驗證部分,以驗證用戶以便接收來自用戶的輸入並更新特定用戶的狀態。

<body>
  <form method = "POST" action = "update2.php">

    <h1>Please enter your user id to update your other details</h1>
    <label>ID</label>
    <input type = "text" name = "ID"><br/>
    <label>Status</label>
    <input type = "text" name = "status">
    <br/>
    <input type = "submit" name = "update">

 </form>
</body>

HTML表單僅支持GET和POST。 僅方法屬性允許html格式的GET和POST請求。 因此,您不能在方法屬性中設置PUT方法類型。 在方法屬性中更改方法類型。 根據HTML標准,您不能這樣做。

 <form method = "PUT" action = "update2.php">

更改您的方法屬性,例如GET或POST。

<form method = "GET" action = "update2.php">

由於錯誤的Mehtod屬性值,您的if條件不能成立。 您總是從以下位置獲得GET價值:

 if($_SERVER['REQUEST_METHOD'] == "PUT")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM