我有这个html表格
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Please Input Below Information</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form method="POST" action="model.php" class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Model Code *</label>
<div class="col-sm-10">
<input type="text" name="ModelCode" class="form-control" id="inputEmail3" placeholder="e.g KTI">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Model Name *</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ModelName" id="inputPassword3" placeholder="e.g 0002">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Units *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelUnit" style="width: 100%;">
<option value="" selected disabled>Choose Model Unit</option>
<?php
$sql = mysqli_query($con, "select departmentname from department");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['departmentname']; ?>"><?php echo $row['departmentname']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Hour Theroy *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelHourT" style="width: 100%;">
<option value="" selected disabled>Choose Model Hour</option>
<?php
$sql = mysqli_query($con, "select GroupTeory from grouptheory");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['GroupTeory']; ?>"><?php echo $row['GroupTeory']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Hour Practice *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelHourP" style="width: 100%;">
<option value="" selected disabled>Choose Model Practice</option>
<?php
$sql = mysqli_query($con, "select GroupPractical from grouppractical");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['GroupPractical']; ?>"><?php echo $row['GroupPractical']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Model Type *</label>
<div class="col-sm-10">
<input type="text" name="ModelType" class="form-control" id="inputEmail3" placeholder="e.g KTI">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Semister *</label>
<div class="col-sm-10">
<select class="form-control" style="width: 100%;" name="SemsterID">
<option value="" selected disabled>Choose Model Type</option>
<?php
$sql = mysqli_query($con, "select Semester from semester");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['Semester']; ?>"><?php echo $row['Semester']; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<input type="submit" name="submit" class="btn btn-info pull-right" value="Submit" />
</div>
<!-- /.box-footer -->
</form>
</div>
这是我的php插入功能
include("Connection.php");
if(isset($_POST['submit']))
{
echo "<script>alert($query1)</script>";
$ModelCode = mysqli_real_escape_string($con,$_POST['ModelCode']);
$ModelName = mysqli_real_escape_string($con,$_POST['ModelName']);
$ModelUnit = mysqli_real_escape_string($con,$_POST['ModelUnit']);
$ModelHourT =mysqli_real_escape_string($con,$_POST['ModelHourT']);
$ModelHourP = mysqli_real_escape_string($con,$_POST['ModelHourP']);
$ModelType = mysqli_real_escape_string($con,$_POST['ModelType']);
$SemsterID = mysqli_real_escape_string($con,$_POST['SemsterID']);
$query1 = mysqli_query($con, "INSERT INTO 'model' (ModelCode,ModelName,ModelUnit,ModelHourTheory,ModelHourPractical,ModelType,StageID) VALUES ('$ModelCode','$ModelName','$ModelUnit','$ModelHourT','$ModelHourP','$ModelType' ,'$SemsterID')");
echo "<script>alert($query1)</script>";
}
它不起作用....我不是没有发生什么!即使我已经将表的字段与数据库的名称进行比较......但它仍然无效......任何人都知道什么是问题?
答案 0 :(得分:0)
您不应该对表名使用单引号(在这种情况下,单引号是字面值)
假设您的表名为model,您应该使用
$query1 = mysqli_query($con,
"INSERT INTO model (ModelCode, ModelName,ModelUnit,
ModelHourTheory,ModelHourPractical,ModelType,StageID)
VALUES ('$ModelCode','$ModelName','$ModelUnit',
'$ModelHourT','$ModelHourP','$ModelType','$SemsterID')");