2016-09-19 147 views
-2
<form name="screenDishForm" action="bentoQuery.php" method="POST"> 
     <!--Label and input for the name of dish --> 
      <label class="contentLabel"> Name: </label><br> 
      <input class="inputField" type="text" id="dishName" name="dishName" placeholder="E.g. Beef Teriyaki" required><br> 

    <!-- Label and Drop down list for the type of dish --> 
      <label class="contentLabel"> Type: </label><br> 
      <select class = "inputField" id="dishType" name = "dishType"> 
        <option value="mainDish">Main Dish</option> 
        <option value="sideDish">Side Dish</option> 
        <option value="soup">Soup</option> 
      </select><br> 

    <!--Label and input for the price of dishes --> 
      <label class="contentLabel"> Price: </label> <br> 
      <input class="inputField" type="number" minimum="0" id="dishPrice" name="dishPrice" required><br> 

    <!--Button that will be used to register the dishes. --> 
      <button class="btnRegister" type="submit" name="submit"> Register Dish </button> 

</form> 

這是我的形式,我命名爲bentoApp.php如何從表格中獲取數據

<?php 
    require_once 'dbConn.php'; 

     $dishName = $_POST['dishName']; 
     $dishType = $_POST['dishType']; 
     $dishPrice = $_POST['dishPrice']; 

     $sql = "INSERT INTO dish(dishName, dishType, dishPrice) 
     VALUES ('$this->dishName', '$this->dishType', '$this->dishPrice')"; 

    ?> 

這是我BentoQuerry.php內容

我怎麼獲取數據的形式? 原來的錯誤

Fatal error: Using $this when not in object context in

+0

那麼,所有這些在哪裏?如果你沒有使用類,那你爲什麼使用'$ this->'而不是變量?您也從未執行過查詢,也無法知道您使用哪個API進行連接。 –

回答

0

只要用你的變量$ dishName,$ dishType,$ dishPrice。

$this用於指您正在使用它的對象的當前實例。你目前沒有使用任何物體。

0

從您的mysql值變量中刪除$this->。我假設你在這裏犯了一個錯誤,如果不是這樣的話,你的問題是你把變量賦值給了變量,但是沒有使用它們。你寫他們就好像你指的是你目前沒有的對象實例,甚至是不正確的。

這就是你的代碼應該看起來像什麼。

<?php 
    require_once 'dbConn.php'; 

     $dishName = $_POST['dishName']; 
     $dishType = $_POST['dishType']; 
     $dishPrice = $_POST['dishPrice']; 

     $sql = "INSERT INTO dish(dishName, dishType, dishPrice) 
     VALUES ('$dishName', '$dishType', $dishPrice)"; 

    ?> 
+0

我在......之前發了一個錯誤,但這是正確的 –

+0

'VALUES($ dishName,$ dishType,$ dishPrice)'仍然會拋出一個錯誤,只是一個不同的錯誤。另外,該查詢從來沒有執行過。 –

+0

你有什麼錯誤? –

相關問題