在调用index.php时出现HTML页面 提交值时,不会显示错误并刷新页面。但是,数据库表中不会显示任何值。 也没有显示错误。 请提出解决方案。
数据库名称:cardb 表名:汽车
PHP代码
<?php
include('index.html');
$conn = new mysqli('localhost','root','','cardb');
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$seat_value=$_POST['seat'];
$fuel_value=$_POST['fuel'];
$class_value=$_POST['class'];
$body_value=$_POST['bodystyle'];
$sql = "INSERT INTO car (`seat`,fuel,class,bodystyle)
VALUES ('$seat_value','$fuel_value','$class_value','$body_value')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
$last_id = $conn->insert_id;
echo "New record created successfully. Last inserted ID is: " . $last_id;
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
HTML
<form action="index.php" method="POST" id="inputs">
<div id="specs" class="content-section-b" style="border-top: 0">
<div class="container">
<div class="col-md-6 col-md-offset-3 text-center wrap_title">
<h2>Specification</h2>
<p class="lead" style="margin-top:0">Tell us what you are looking for</p>
</div>
<div class="row">
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="img/icon/tweet.svg" alt="Generic placeholder image">
<h3>Fuel</h3>
<select id="dropdown1" name="fuel">
<option value="any" selected >No Preference</option>
<option value="petrol">Petrol</option>
<option value="diesel">Diesel</option>
</select>
</div>
<div class="col-sm-4 wow fadeInDown text-center">
</div>
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="img/icon/tweet.svg" alt="Generic placeholder image">
<h3>Seating</h3>
<select id="dropdown2" name="seat">
<option value="any" selected >No Preference</option>
<option value="seat45">4/5</option>
<option value="seat67">6/7</option>
<option value="seat8">8</option>
</select>
</div>
</div> <!-- row -->
<div class="row">
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="img/icon/tweet.svg" alt="Generic placeholder image">
<h3>Body Style</h3>
<select id="dropdown3" name="bodystyle">
<option value="any" selected >No Preference</option>
<option value="sedan">Sedan</option>
<option value="hatchback">Hatchback</option>
<option value="mpv">MPV</option>
<option value="suv">SUV</option>
</select>
</div>
<div class="col-sm-4 wow fadeInDown text-center">
</div>
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="img/icon/tweet.svg" alt="Generic placeholder image">
<h3>Class</h3>
<select id="dropdown4" name="class">
<option value="any" selected >No Preference</option>
<option value="economy">Economy</option>
<option value="executive">Executive</option>
<option value="buisness">Buisness</option>
</select>
</div>
</div> <!-- row -->
</div>
</div>
</form>
<div id="specs" vertical-align: top;>
<!-- SUBMIT --> <center> <button type="submit" class="btn btn-embossed btn-primary view" form="inputs" value="Submit">Submit</button> </center>
</div>
答案 0 :(得分:2)
除了what I wrote in comments关于你如何访问该文件(这很重要):
您的<button type="submit" class="btn btn-embossed btn-primary view" form="inputs" value="Submit">Submit</button>
在<{1}}标记之外。
补充说明;您的代码对SQL注入是开放的。使用准备好的声明。
参考文献: