我想使用ajax.ajax成功运行函数警告run.but数据将数据插入名为vacancy的mysql表中。但数据不保存在table.and错误是occer.i我是php和ajax的新手
html代码
<form class="form-horizontal" action="postvaccode2.php" type="post">
<fieldset>
<!-- Form Name -->
<legend>Post Vacancy</legend>
<!-- Select Basic -->
<div class="form-group">
<div class="col-md-5">
<select id="cato" name="cato" class="form-control" id="cato">
<option value="IR">IT</option>
<option value="USA">Finance</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-6">
<input id="comid" name="comid" type="text" placeholder="comid" class="form-control input-md" required="" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-6">
<input id="loc" name="loc" type="text" placeholder="city or town" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="qul" name="qul" type="text" placeholder="qulification" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="indate" name="indate" type="date" placeholder="indate" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<div class="col-md-4">
<input id="expdate" name="expdate" type="date" placeholder="expdate" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="gpa" name="gpa" type="text" placeholder="gpa" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="des" name="des" type="text" placeholder="description" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="title" name="title" type="text" placeholder="title" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="comname" name="comname" type="text" placeholder="name" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<input id="vacpost" name="vacpost" type="submit" class="form-control input-md">
</div>
</div>
</fieldset>
</form>
脚本
</script>
<script>
$('#vacpost').click(function () {
$.ajax({
type: "POST",
url: "postvaccode2.php",
data:{id:$('#comid').val(),cato:$('#cato').val(),loc:$('#loc').val(),quli:$('#qul').val(),indate:$('#indate').val(),expdate:$('#expdate').val(),gpa:$('#gpa').val(),des:$('#des').val(),title:$('#title').val(),comname:$('#comname').val()},
success:function () {
alert('Sccessfuly Post the Job vacency');
location.reload(true);
}
});
});
</script>
postvaccode2.php
<?php
$conn=mysqli_connect("localhost","root","","internship");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id=$_POST['id'];
$cato=$_POST['cato'];
$loc=$_POST['loc'];
$quli=$_POST['quli'];
$indate=$_POST['indate'];
$expdate=$_POST['expdate'];
$gpa=$_POST['gpa'];
$des=$_POST['des'];
$title=$_POST['title'];
$comname=$_POST['comname'];
$sql="insert into vacancy(companyid,catogary,location,qulification,indate,expectgpa,description,title,expdate,companyname) values('$id','$cato','$loc','$quli','$indate','$gpa','$des','$title','$expdate','$comname',)";
$conn->query($sql);
?>