我使用下面的代码将文本框的id和值插入到mysql数据库的表中,id是自动增量,但是这个代码在插入id时不会将任何值插入到表的列中,请帮忙。 / p>
<div>
<?php
if (isset($_POST['addtag']))
{
$tags_dept = $_POST['$tags_dept'];
$query = "INSERT into deptag (tagdep) VALUES ('$tags_dept')";
mysql_query($query);
}
?>
<a href="#" onclick="toggle_visibility('addtag1');">Add Tag for Department</a>
<div id="addtag1" style="display:none;">
<form name="form4" method="post" action="" >
<input type="text" name="tags_dept" />
<input type="submit" value="ADD" name="addtag" />
</form>
</div>
答案 0 :(得分:0)
首先将 MySQL 转换为 MySQLi 。
<html>
<body>
<?php
$con=mysqli_connect("YourHost","Username","Password","YourDatabase");
if(mysqli_connect_errno()){
echo "Error".mysqli_connect_error();
}
if (isset($_POST['addtag']))
{
$tagsdept = $_POST['$tagsdept'];
$tagsdept = mysqli_real_escape_string($con,$tagsdept); /* PREVENT A BIT OF SQL INJECTION */
mysqli_query($con,"INSERT into deptag (tagdep) VALUES ('$tagsdept')");
}
?>
<a href="#" onclick="toggle_visibility('addtag1');">Add Tag for Department</a>
<div id="addtag1" style="display:none;">
<form name="form4" method="post" action="" >
<input type="text" name="tagsdept" />
<input type="submit" value="ADD" name="addtag" />
</form>
</div>
</body>
</html>