我已经为表单面板中的表单编写了一个php代码。但是这些值并没有进入数据库。我已经在php文件的顶部编写了php代码。提交表单提交后,当php代码写在标签之前的文件顶部并且从表单中获取的值未插入到表单时,它将转到第二个选项卡数据库。为什么会那样?我不知道如何纠正这个问题。任何人都可以帮我吗?
php代码:
<?php
include("database.php");
if(isset($_REQUEST['save'])){
if($_POST['start']!=''&&$_POST['end']!=''&&$_POST['firstname']!=''&&$_POST['lastname']!=''&&$_POST['age']!='')
{
$start = $_POST['start'];
$end = $_POST['end'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$cur = date("d.m.Y");
$j = 'CUS'.rand(1,1000000);
$sql = "insert into tbl_customer(id,customer_id,firstname,lastname,age,rentalfromdate,rentaltodate,date) values(' ','$j','$firstname','$lastname','$age','$start','$end','$cur')";
mysqli_query($con,$sql) or die(mysqli_error($con));
}
}
?>
标签:
<div class="tab-pane active" role="tabpanel" id="step1">
<div class="step1">
<div class="spec">
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
<div class="main_cont">
<div class="main-agileits">
<div class="register-box">
<form name="customer" id="customer" method="post" action="#step1">
<div id="flight-datepicker" class="input-daterange input-group">
<div class="col-md-6 s_pad">
<label>First day of rental</label><span class="fontawesome-calendar"></span>
<input type="text" id="start-date" name="start" placeholder="Select Date" data-date-format="DD, MM d" class="input-sm form-control" /><span class="date-text date-depart"></span>
</div>
<div class="col-md-6 s_pad">
<label>Last day of rental</label><span class="fontawesome-calendar"></span>
<input type="text" id="end-date" name="end" placeholder="Select Date" data-date-format="DD, MM d" class="input-sm form-control"/><span class="date-text date-return"></span>
</div>
</div>
<div>
<div class="form-group col-md-12 s_pad">
<label for="exampleInputEmail1">First Name</label>
<input type="text" class="form-control" id="exampleInputEmail1" name="firstname" placeholder="First Name" />
</div>
<div class="form-group col-md-12 s_pad">
<label for="exampleInputEmail1">Last Name</label>
<input type="text" class="form-control" id="exampleInputEmail1" name="lastname" placeholder="Last Name" />
</div>
<div class="form-group col-md-6 s_pad">
<label for="exampleInputEmail1" class="ctred">Age only if under 18</label>
<input type="text" class="form-control" name="age" id="exampleInputName" placeholder="Age">
</div>
</div>
<div>
<button type="submit" name="save" class="btn btn-primary mag_top2 next-step">Continue</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
这样做。然后您将收到错误或成功消息: -
if (mysqli_query($con, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
答案 1 :(得分:0)
我希望id字段是主键,因此你不需要在sql查询中使用它,所以请尝试以下查询。
$sql = "insert into tbl_customer(customer_id,firstname,lastname,age,rentalfromdate,rentaltodate,date) values('$j','$firstname','$lastname','$age','$start','$end','$cur')";