我正在尝试使用Redbeans将数据从Web表单存储到数据库中,但无法正常工作。我已经确保该数据库已连接。我正在使用针对Web和SQL的apache xampp服务器。 这是我的代码
表格
<head>
</head>
<?php
require "validatecar.php";
?>
<body>
<form method="POST">
Model <input type="text" name="Model">
Manufacturing Company <input type="text" name="Company">
Pessenger Capacity <input type="number" name="Pessenger">
Luggage Capacty <input type="number" name="Luggage">
Doors <input type="number" name="Doors">
Transmission <input type="text" name="Transmission">
Stereo <input type="text" name="Stereo">
Air Conditioning <input type="text" name="AC">
Image <input type="file" name="Image">
<input type="submit" name="Submit">
</form>
</body>
验证
<?php
include "dbconnection.php";
?>
<?php
if(isset($_POST['Submit']))
{
$model = $_POST['Model'];
$company = $_POST['Company'];
$pessenger = $_POST['Pessenger'];
$luggage = $_POST['Luggage'];
$doors = $_POST['Doors'];
$transmission = $_POST['Transmission'];
$stereo = $_POST['Stereo'];
$ac = $_POST['AC'];
$image = $_POST['Image'];
$cars = R::dispense('cars');
$cars->model = $model;
$cars->company = $company;
$cars->pessenger = $pessenger;
$cars->luggage = $luggage;
$cars->doors = $doors;
$cars->transmission = $transmission;
$cars->stereo = $stereo;
$cars->ac = $ac;
$cars->image = $image;
R::store($cars);
R::close();
}
?>
如果您可以告诉我我在做什么错以及如何解决,那将非常有帮助。预先感谢。
答案 0 :(得分:0)
您已经开始使用首字母大写来命名。但是由于某种原因,您的提交名称不符合您的命名约定。
将$_POST['Submit']
都命名为小写'submit'
而不是Submit
时,您正在寻找<?php
var_dump($_POST); // Added for Debug - View what is being posted.
if(isset($_POST['Submit']))
{
//... Rest of code here
,因此存储在数据库中的代码将永远不会运行。
如果要在$ _POST上执行var_dump()或print_r()。
I.E。例如,在您的validate.php中,在进行if测试之前,您将看到正在“发布”的内容。
<input type="submit" name="submit">
因此,在您的表单中,您的提交输入中包含“名称”值的拼写错误。
<input type="submit" name="Submit">
应该是...
font-face