<?php
include("database.php");
if(isset($_POST['submit']))
{
$category=$_POST["category"];
$ittitle=$_POST["ittitle"];
$itname=$_POST["itname"];
$itrole=$_POST["itrole"];
$itsalary=$_POST["itsalary"];
$btitle=$_POST["btitle"];
$bname=$_POST["bname"];
$brole=$_POST["brole"];
$bsalary=$_POST["bsalary"];
$gtitle=$_POST["gtitle"];
$gname=$_POST["gname"];
$grole=$_POST["grole"];
$gsalary=$_POST["gsalary"];
$result=mysql_query("insert into test(ittitle,itname,itrole,itsalary,btitle,bname,brole,bsalary,gtitle,gname,grole,gsalary)values('$_POST[ittitle]','$_POST[itname]','$_POST[itrole]','$_POST[itsalary]','$_POST[btitle]','$_POST[bname]','$_POST[brole]','$_POST[bsalary]','$_POST[gtitle]','$_POST[gname]','$_POST[grole]','$_POST[gsalary]')");
echo "Inserted Successfully";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
}
.it{ background: white; }
.bank{ background: white; }
.govt{ background: white; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="it"){
$(".box").hide();
$(".it").show();
}
if($(this).attr("value")=="bank"){
$(".box").hide();
$(".bank").show();
}
if($(this).attr("value")=="govt"){
$(".box").hide();
$(".govt").show();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select name="category">
<option>Choose Category</option>
<option value="it">it</option>
<option value="bank">bank</option>
<option value="govt">govt</option>
</select>
</div>
<div class="it box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="ittitle"></td></tr>
<tr>
<td><b> IT Name</td>
<td><input type="text" name="itname"></td></tr>
<tr>
<td><b> IT Job Role</td>
<td><input type="text" name="itrole"></td></tr>
<tr>
<td><b> IT Salary</td>
<td><input type="text" name="itsalary"></td></tr>
</table></div>
<div class="bank box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="btitle"></td></tr>
<tr>
<td><b> Bank Name</td>
<td><input type="text" name="bname"></td></tr>
<tr>
<td><b> Bank Job Role</td>
<td><input type="text" name="brole"></td></tr>
<tr>
<td><b> Bank Salary</td>
<td><input type="text" name="bsalary"></td></tr>
</table></div>
<div class="govt box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="gtitle"></td></tr>
<tr>
<td><b> Govt Name</td>
<td><input type="text" name="gname"></td></tr>
<tr>
<td><b> Govt Job Role</td>
<td><input type="text" name="grole"></td></tr>
<tr>
<td><b> Govt Salary</td>
<td><input type="text" name="gsalary"></td></tr>
</table></div>
<input type="submit" name="submit" value="submit"/>
</body>
</html>
提交后无法插入数据库。请告诉我需要进行的更改。
答案 0 :(得分:0)
您需要更改许多内容,但要解决此问题,您需要将mysql_query修复为此(注意括号):
$ result = mysql_query(“插入测试(ittitle,itname,itrole,itsalary,btitle,bname,brole,bsalary,gtitle,gname,grole,gsalary)值('{$ _ POST [”ittitle“]}' '的 {$ _ POST [ “itname”]} 强>', '{$ _ POST [ “itrole”]}', '{$ _ POST [ “itsalary”]}',“{$ _ POST [” BTITLE“]} ' '{$ _ POST [ ”BNAME“]}', '{$ _ POST [ ”brole“]}', '{$ _ POST [ ”bsalary“]}','{$ _ POST [ ”gtitle“ ]}”, '{$ _ POST [ “的gname”]}', '{$ _ POST [ “grole”]}', '{$ _ POST [ “gsalary”]}')“);
答案 1 :(得分:0)
<?php
include("database.php");
if(isset($_POST['submit']))
{
$category=$_POST["category"];
$ittitle=$_POST["ittitle"];
$itname=$_POST["itname"];
$itrole=$_POST["itrole"];
$itsalary=$_POST["itsalary"];
$btitle=$_POST["btitle"];
$bname=$_POST["bname"];
$brole=$_POST["brole"];
$bsalary=$_POST["bsalary"];
$gtitle=$_POST["gtitle"];
$gname=$_POST["gname"];
$grole=$_POST["grole"];
$gsalary=$_POST["gsalary"];
$result=mysql_query("insert into test(ittitle,itname,itrole,itsalary,btitle,bname,brole,bsalary,gtitle,gname,grole,gsalary)values('$_POST[ittitle]','$_POST[itname]','$_POST[itrole]','$_POST[itsalary]','$_POST[btitle]','$_POST[bname]','$_POST[brole]','$_POST[bsalary]','$_POST[gtitle]','$_POST[gname]','$_POST[grole]','$_POST[gsalary]')");
echo "Inserted Successfully";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
}
.it{ background: white; }
.bank{ background: white; }
.govt{ background: white; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="it"){
$(".box").hide();
$(".it").show();
}
if($(this).attr("value")=="bank"){
$(".box").hide();
$(".bank").show();
}
if($(this).attr("value")=="govt"){
$(".box").hide();
$(".govt").show();
}
});
}).change();
});
</script>
</head>
<body>
<form action="" method="get" name="form1">
<div>
<select name="category">
<option>Choose Category</option>
<option value="it">it</option>
<option value="bank">bank</option>
<option value="govt">govt</option>
</select>
</div>
<div class="it box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="ittitle"></td></tr>
<tr>
<td><b> IT Name</td>
<td><input type="text" name="itname"></td></tr>
<tr>
<td><b> IT Job Role</td>
<td><input type="text" name="itrole"></td></tr>
<tr>
<td><b> IT Salary</td>
<td><input type="text" name="itsalary"></td></tr>
</table></div>
<div class="bank box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="btitle"></td></tr>
<tr>
<td><b> Bank Name</td>
<td><input type="text" name="bname"></td></tr>
<tr>
<td><b> Bank Job Role</td>
<td><input type="text" name="brole"></td></tr>
<tr>
<td><b> Bank Salary</td>
<td><input type="text" name="bsalary"></td></tr>
</table></div>
<div class="govt box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="gtitle"></td></tr>
<tr>
<td><b> Govt Name</td>
<td><input type="text" name="gname"></td></tr>
<tr>
<td><b> Govt Job Role</td>
<td><input type="text" name="grole"></td></tr>
<tr>
<td><b> Govt Salary</td>
<td><input type="text" name="gsalary"></td></tr>
</table></div>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
答案 2 :(得分:0)
代码中没有任何形式。定义及其方法为方法=&#34; post&#34;
答案 3 :(得分:0)
试试此代码
<?php
require_once("database.php");
if(isset($_POST['submit']))
{
$category=$_POST["category"];
$ittitle=$_POST["ittitle"];
$itname=$_POST["itname"];
$itrole=$_POST["itrole"];
$itsalary=$_POST["itsalary"];
$btitle=$_POST["btitle"];
$bname=$_POST["bname"];
$brole=$_POST["brole"];
$bsalary=$_POST["bsalary"];
$gtitle=$_POST["gtitle"];
$gname=$_POST["gname"];
$grole=$_POST["grole"];
$gsalary=$_POST["gsalary"];
$result=mysql_query("insert into test(`ittitle`,`itname`,`itrole`,`itsalary`,`btitle`,`bname`,`brole`,`bsalary`,`gtitle`,`gname`,`grole`,`gsalary`) values('$_POST[ittitle]','$_POST[itname]','$_POST[itrole]','$_POST[itsalary]','$_POST[btitle]','$_POST[bname]','$_POST[brole]','$_POST[bsalary]','$_POST[gtitle]','$_POST[gname]','$_POST[grole]','$_POST[gsalary]')");
echo "Inserted Successfully";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Using Selectbox</title>
<style type="text/css">
.box{
padding: 20px;
display: none;
margin-top: 20px;
}
.it{ background: white; }
.bank{ background: white; }
.govt{ background: white; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="it"){
$(".box").hide();
$(".it").show();
}
if($(this).attr("value")=="bank"){
$(".box").hide();
$(".bank").show();
}
if($(this).attr("value")=="govt"){
$(".box").hide();
$(".govt").show();
}
});
}).change();
});
</script>
</head>
<body>
<form action="#">
<div>
<select name="category">
<option>Choose Category</option>
<option value="it">it</option>
<option value="bank">bank</option>
<option value="govt">govt</option>
</select>
</div>
<div class="it box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="ittitle"></td></tr>
<tr>
<td><b> IT Name</td>
<td><input type="text" name="itname"></td></tr>
<tr>
<td><b> IT Job Role</td>
<td><input type="text" name="itrole"></td></tr>
<tr>
<td><b> IT Salary</td>
<td><input type="text" name="itsalary"></td></tr>
</table></div>
<div class="bank box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="btitle"></td></tr>
<tr>
<td><b> Bank Name</td>
<td><input type="text" name="bname"></td></tr>
<tr>
<td><b> Bank Job Role</td>
<td><input type="text" name="brole"></td></tr>
<tr>
<td><b> Bank Salary</td>
<td><input type="text" name="bsalary"></td></tr>
</table></div>
<div class="govt box"><table border="1" style="width:250px">
<tr>
<td><b>Title</td>
<td><input type="text" name="gtitle"></td></tr>
<tr>
<td><b> Govt Name</td>
<td><input type="text" name="gname"></td></tr>
<tr>
<td><b> Govt Job Role</td>
<td><input type="text" name="grole"></td></tr>
<tr>
<td><b> Govt Salary</td>
<td><input type="text" name="gsalary"></td></tr>
</table></div>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
答案 4 :(得分:0)
$result=mysql_query("insert into test(ittitle,itname,itrole,itsalary,btitle,bname,brole,bsalary,gtitle,gname,grole,gsalary)
values('$ittitle','$itname','$itrole','$itsalary','$btitle','$bname','$brole','$bsalary','gtitle','$gname','$grole','$gsalary')");