【发布时间】:2016-09-19 01:12:45
【问题描述】:
<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')";
?>
这是我的 BentoQuery.php 的内容
我将如何获取表单的数据? 原来是一个错误
致命错误:当不在对象上下文中时使用 $this
【问题讨论】:
-
那么,这一切的课程在哪里?如果您不使用类,那么为什么要使用
$this->而不是变量?您也从未执行过查询,我们也无法知道您使用哪个 API 进行连接。