我一直试图在我的数据库中插入数据但没有成功。我不知道我做错了什么......没有出现错误......也许我的文件路径错了?我正在使用准备好的陈述。我一直在几个数据库中插入数据,只要我记得没有问题。第一次发生在我身上。
文件路径逻辑:
-includes
--config.php
-user
--tables
---form.php
---query.php
的config.php
<?php
header('Content-Type: text/html; charset=iso-8859-1');
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root');
define('DB_DATABASE', 'myDB');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
form.php的
<form id="addNewCompanyForm" class="form" method="POST" action="query.php">
<input id='titleName' class='form-control formBlock' name='title' value='' type='text' placeholder="Name...">
<select id='type' class='form-control formBlock' name='type'></select>
<textarea id='description' class='form-control formBlock' name='description' value='' placeholder="Enter details here..."></textarea>
<input id='address' class='form-control formBlock' name='address' value='' type='text' placeholder="Address">
<select name="country" id='country' class='form-control formBlock' name='country' value='' type='text' placeholder="Country"></select>
<select id='timezone' class='form-control formBlock' name="timezone"></select>
<input id="submit" type="submit" class="formBlock btn btn-success" data-dismiss="modal" value="Enter Data"/>
</form>
query.php
<?php
require_once '../../includes/config.php';
// prepare and bind
$stmt = $db->prepare("INSERT INTO companystructures (title, description, address, type, country, timezone) VALUES (?, ?, ?,?,?,?)");
$stmt->bind_param("ssssss", $title, $type, $description, $address, $country, $timezone);
// set parameters and execute
$title = $_POST['title'];
$type = $_POST['type'];
$description= $_POST['description'];
$address = $_POST['address'];
$country = $_POST['country'];
$timezone = $_POST['timezone'];
$stmt->execute();
//echo "New records created successfully";
$stmt->close();
$db->close();
?>