<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的内容
我如何获取表格的数据? 结果是错误
致命错误:在
中不在对象上下文中时使用$ this
答案 0 :(得分:0)
只需使用你的变量$ dishName,$ dishType,$ dishPrice。
$this
用于指代您正在使用它的对象的当前实例。您目前没有使用任何对象。
答案 1 :(得分:0)
从mysql Values变量中删除$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)";
?>