我插入了产品类别表格,您可以在其中输入标题和说明,当我填写表格时,我的警报消息不起作用并且数据没有插入数据库中,但是我的window.open命令起作用并且显示我输入的输入。该文件包含在具有数据库连接的index.php中。也不会显示任何错误。
注意:下面的代码全部放在一个文件中,我刚刚将其拆分了
<?php
if(!isset($_SESSION['admin_email'])){
echo "<script>window.open('login.php','_self')</script>";
}else{
?>
<div class="row"><!-- row 1 Begin -->
<div class="col-lg-12"><!-- col-lg-12 Begin -->
<ol class="breadcrumb"><!-- breadcrumb Begin -->
<li><!-- li Begin -->
<i class="fa fa-dashboard"></i> Dashboard / Insert Product Category
</li><!-- li Finished -->
</ol><!-- breadcrumb Finished -->
</div><!-- col-lg-12 Finished -->
</div><!-- row 1 Finished -->
<div class="row"><!-- row 2 Begin -->
<div class="col-lg-12"><!-- col-lg-12 Begin -->
<div class="panel panel-default"><!-- panel panel-default Begin -->
<div class="panel-heading"><!-- panel-heading Begin -->
<h3 class="panel-title"><!-- panel-title Begin -->
<i class="fa fa-money fa-fw"></i> Insert Product Category
</h3><!-- panel-title Finished -->
</div><!-- panel-heading Finished -->
<div class="panel-body"><!-- panel-body Begin -->
<form action="" class="form-horizontal"><!-- form-horizontal Begin -->
<div class="form-group"><!-- form-groups Begin -->
<label for="" class="control-label col-md-3"><!-- control-label col-md-3 Begin --> Product Category Title
</label><!-- control-label col-md-3 Finished -->
<div class="col-md-6"><!-- col-md-6 Begin -->
<input name="p_cat_title" type="text" class="form-control">
</div><!-- col-md-6 Finished -->
</div><!-- form-groups Finished -->
<div class="form-group"><!-- form-groups Begin -->
<label for="" class="control-label col-md-3"><!-- control-label col-md-3 Begin --> Product Category Description
</label><!-- control-label col-md-3 Finished -->
<div class="col-md-6"><!-- col-md-6 Begin -->
<textarea type="text" name="p_cat_desc" id="" cols="30" rows="10" class="form-control"></textarea>
</div><!-- col-md-6 Finished -->
</div><!-- form-groups Finished -->
<div class="form-group"><!-- form-groups Begin -->
<label for="" class="control-label col-md-3"><!-- control-label col-md-3 Begin -->
</label><!-- control-label col-md-3 Finished -->
<div class="col-md-6"><!-- col-md-6 Begin -->
<input value="Submit" name="submit" type="submit" class="form-control btn btn-primary">
</div><!-- col-md-6 Finished -->
</div><!-- form-groups Finished -->
</form><!-- form-horizontal Finished -->
</div><!-- panel-body Finished -->
</div><!-- panel panel-default Finished -->
</div><!-- col-lg-12 Finished -->
</div><!-- row 2 Finished -->
<?php
if (isset($_POST['submit'])) {
$p_cat_title = $_POST['p_cat_title'];
$p_cat_desc = $_POST['p_cat_desc'];
$insert_p_cat = "insert into product_categories (p_cat_title,p_cat_desc) values ('$p_cat_title,$p_cat_desc')";
$run_p_cat = mysqli_query($con,$insert_p_cat);
if ($run_p_cat) {
echo "<script>alert('Your New Product Category Has Been Added')</script>";
echo "<script>window.open('index.php?view_p_cats','_self')</script>";
}
}?> <?php } ?>
答案 0 :(得分:1)
如果未指定,则<form>
的方法为GET,因此if (isset($_POST['submit']))
为false。
您应该将方法POST
添加到表单标签
<form method="POST" action="index.php">
答案 1 :(得分:0)
尝试更改以更改
('$p_cat_title,$p_cat_desc')
到
('$p_cat_title','$p_cat_desc')
我认为您忘记在仅插入一个值的变量末尾添加'