2016-09-19 146 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

你有什么错误? –

相关问题