我正在使用php和MySQL。当我提交表单数据时,数据表中没有存储' plantation_journal_nursery_details'。我被困在这里。任何人都可以建议我,我该如何解决这个问题?先谢谢你们。代码如下:
create_journal.php
<form action="data_fetch.php" action="post">
<div class="row">
<div class="col-sm-4">
<h4 style="font-size: 16px;padding-left: 15px;"><b>Nursery Location:</b></h4><br>
<div align="right" style="padding-right: 10px;">
<label style="font-weight:300;font-size: 15px">Location:</label>
<input type="text" name="location" id="location" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Area:</label>
<input type="text" name="area1" id="area1" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">type of Nursey:</label>
<select name="type_of_nursery" id="type_of_nursery" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
<label style="font-weight:300;font-size: 15px">Centranl Nursery Name:</label>
<select name="central_nursery_name" id="central_nursery_name" style="width:40%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
<label style="font-weight:300;font-size: 15px">State Nursery Name:</label>
<input type="text" name="state_nursery_name" id="state_nursery_name" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
</div>
</div>
<div class="col-sm-4">
<h4 style="font-size: 16px;padding-left: 15px;"><b>Size of Each Bed:</b></h4><br>
<div align="right" style="padding-right: 10px;">
<label style="font-weight:300;font-size: 15px">Mother Bed Size:</label>
<input type="text" name="mother_bed_size" id="mother_bed_size" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_m" id="quantity_m" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br><br><br>
<label style="font-weight:300;font-size: 15px">Source of Seed:</label>
<select name="source_of_seed" id="source_of_seed" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
</div>
</div>
<div class="col-sm-4">
<div align="right" style="padding-right: 10px; padding-top: 40px">
<label style="font-weight:300;font-size: 15px">Polypot Bed Size:</label>
<input type="text" name="polypot_bed_size" id="polypot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_p" id="quantity_p" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br><br>
<label style="font-weight:300;font-size: 15px">Hycopot Bed Size:</label>
<input type="text" name="hycopot_bed_size" id="hycopot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_h" id="quantity_h" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
</div>
</div>
</div>
<div class="row">
<div align="right" style="padding-right: 10px;">
<input class="btn btn-info" type="submit" name="submit16" value="Add" onclick="move7()">
</div>
</div>
</form>
data_fetch.php
<?php
$con=mysqli_connect("localhost","root","","forestdb");
if(isset($_POST['submit16'])){
$location=$_POST['location'];
$area1=$_POST['area1'];
$type_of_nursery=$_POST['type_of_nursery'];
$central_nursery_name=$_POST['central_nursery_name'];
$state_nursery_name=$_POST['state_nursery_name'];
$mother_bed_size=$_POST['mother_bed_size'];
$quantity_m=$_POST['quantity_m'];
$source_of_seed=$_POST['source_of_seed'];
$polypot_bed_size=$_POST['polypot_bed_size'];
$quantity_p=$_POST['quantity_p'];
$hycopot_bed_size=$_POST['hycopot_bed_size'];
$quantity_h=$_POST['quantity_h'];
$query="SELECT plantation_journal_no from plantation_journal_basic_details where plantation_journal_no=(select max(plantation_journal_no) from plantation_journal_basic_details);";
$res=mysqli_query($con,$query);
$row=mysqli_fetch_assoc($res);
$plantation_journal_no=$row['plantation_journal_no'];
$sql="INSERT INTO `plantation_journal_nursery_details`(`plantation_journal_no`, `location`, `area`, `type_of_nursery`, `central_nursery_name`, `state_nursery_name`, `mother_bed_size`, `quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`, `hycopot_bed_size`, `quantity_h`) VALUES ('$plantation_journal_no','$location','$area1','$type_of_nursery','$central_nursery_name','$central_nursery_name','$mother_bed_size','$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p','$hycopot_bed_size','$quantity_h');";
$result=mysqli_query($con,$sql);
if($result){
echo "<script>alert('data submitted.');</script>";
header("Location:create_journal.php");
}
}
?>
答案 0 :(得分:0)
在编辑问题之前,您的插入查询包含...
...VALUES ('$plantation_journal_no',$configurarion','$slope','$water_table_in_...
请注意,您的单引号不匹配。你应该
...VALUES ('$plantation_journal_no','$configurarion','$slope','$water_table_in_...
如果您在查询中检查过错误,则会立即发现此问题。像这样的代码会有所帮助。
if($result){
echo "<script>alert('data submitted.');</script>";
header("Location:create_journal.php");
}
else {
die $mysqli->error;
}
专业提示:格式化代码,这样您就不必水平滚动查看整个查询。通过这种方式检查查询并发现错误要容易得多。您可以使用php's heredoc syntax for string constants来执行此操作。
这就是它的样子。
$sql= <<<INSERTQUERY
INSERT INTO `plantation_journal_nursery_details`
(`plantation_journal_no`, `location`, `area`, `type_of_nursery`,
`central_nursery_name`, `state_nursery_name`, `mother_bed_size`,
`quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`,
`hycopot_bed_size`, `quantity_h`)
VALUES
('$plantation_journal_no','$location','$area1','$type_of_nursery',
'$central_nursery_name','$central_nursery_name','$mother_bed_size',
'$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p',
'$hycopot_bed_size','$quantity_h');
INSERTQUERY;