我的数据库结构看起来像这样; 从PHP保存到MySQL表格
我的代码看起来像这样;
<?php
$email_sql = mysqli_connect('localhost', 'root', 'root', 'myremovalsquote');
// Check connection
if ($email_sql->connect_error) {
die("Connection failed: " . $email_sql->connect_error);
} else { echo 'connected'; }
?>
<?php get_header(); ?>
<section>
<div class="container">
<div class="row">
<div class="col-md-12">
<article>
<h1>Get Your FREE Quotes Now!</h1>
<div class="post">
<form method="post" action="<?php bloginfo('url') ?>/quote">
<ul id="quoteform">
<li class="row">
<div class="col-md-12">
<h2>Where are you moving from?</h2>
<select name="frompc">
<option value="ab">Aberdeen (AB)</option>
<option value="al">St Albans (AL)</option>
</select>
<p>What type of property are you moving from?</p>
<select name="fromtype">
<option value="storage">Storage</option>
<option value="bungalow">Bungalow</option>
<option selected value="house">House</option>
<option value="multistory">Multi-Story</option>
</select>
</div>
</li>
<li class="row">
<div class="col-md-12">
<h2>Move details</h2>
<input type="text" name="movedate" placeholder="DD/MM/YYYY">
<p>Is this date flexible?
<select name="flexible">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></p>
</div>
</li>
<li class="row">
<div class="col-md-12">
<h2>Where are you moving to?</h2>
<select name="topc">
<option value="ab">Aberdeen (AB)</option>
<option value="al">St Albans (AL)</option>
</select>
<select name="totype">
<option value="storage">Storage</option>
<option value="bungalow">Bungalow</option>
<option selected value="house">House</option>
<option value="multistory">Multi-Story</option>
</select>
</div>
</li>
<li class="row">
<div class="col-md-12">
<h2>Extra Services</h2>
<input type="checkbox" name="packaging" value="Packaging">
<input type="checkbox" name="packing" value="Packing">
<input type="checkbox" name="furniture" value="Dismantle & Reassemble Furniture">
</div>
</li>
<li class="row">
<div class="col-md-12">
<h2>Notes/Additions</h2>
<textarea name="notes">Enter text here...</textarea>
</div>
</li>
<li class="row">
<div class="col-md-12">
<h2>Your Details</h2>
Full Name
<input type="text" name="fullname" value="Joe Bloggs">
Contact Number
<input type="text" name="contactnumber">
Email Address
<input type="email" name="email">
</div>
</li>
<li class="row">
<div class="col-md-12">
<input type="submit" name="submit" required="required" value="Get Quotes!" id="emailbutton">
<?php
//CREATE VARIBLES
if(isset($_POST["submit"])) {
$submitdate = date("d/m/Y", strtotime($oldDate));
$frompostcode = $_POST["frompc"];
$fromtype = $_POST["fromtype"];
$movedate = $_POST["movedate"];
$flexible = $_POST["flexible"];
$topostcode = $_POST["topc"];
$totype = $_POST["totype"];
$packing = $_POST["packing"];
$packaging = $_POST["packaging"];
$furniture = $_POST["furniture"];
$notes = $_POST["notes"];
$name = $_POST["fullname"];
$contactnumber = $_POST["contactnumber"];
$email = $_POST["email"];
}
?>
<?php
//IMPORT TO DATABASE
if (!empty($_POST['email'])) {
//CLEANSE VARIBLES
date_default_timezone_set("Europe/London");
$submitdate = date('d/m/y h:i a', time());
//IMPORT
$query = " INSERT INTO `quotes`
('id', 'date', 'fullname', 'email', 'contactnumber', 'movedate', 'flexible', 'fromtype', 'frompostcode', 'totype', 'topostcode', 'notes')
VALUES
(NULL, '".$submitdate."', '".$name."', '".$email."', '".$contactnumber."', '".$movedate."', '".$flexible."', '".$fromtype."', '".$frompostcode."', '".$totype."', '".$topostcode."', '".$notes."'); ";
mysqli_query($query);
echo 'Thankyou <br />';
echo mysqli_error();
echo $query;
mysqli_close($email_sql);
}
?>
</div>
</li>
</ul>
</form>
</div>
</article>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
我不能为我的生命得到的形式保存到数据库中,我学习PHP/SQL,我不能看到我错了,我知道,我需要使用的mysqli在mysql的地方。
你有什么错误吗?但是,如果您正在学习,您可以关注网络上的很多教程。 –
我没有得到任何的错误,这就是问题所在。当我检查数据库时没有输入任何内容。 –
@BradHouston使用try catch块获取错误。 –