到mysql我想用克隆的div包含表单使用此代码插入记录使用jquery
$(document).ready(function() {
$("#button").click(function() {
$("<div class='newclone' id='xxx'><article><form method='post' id='aj'><input type='checkbox'><label>Firstname</label><input type='text' value='' name='firstname'><label>Secondname</label><input type='text' value='' name='secondname'><label>City</label><input type='text' value='' name='city'><input type='hidden' value='4'></article><input type='submit' value='insert' class='one'><button class='two'>Delete</button><button class='three'>Cancel</button></form></div>").appendTo('.clone-container');
});
$('.one').click(function() {
$.ajax({
type: "POST",
url: "insert.php",
data: $("#aj").serialize(),
success: function() {
alert('Inserted!');
}
});
});
});
这是php文件
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("clone", $con);
$firstname=$_POST['firstname'];
$secondname=$_POST['secondname'];
$city=$_POST['city'];
mysql_query("INSERT INTO clone(firstname,secondname,city) VALUES ('$firstname','$secondname','$city')");
插入一条记录到数据库编辑
问题是,似乎没有发布
什么是错误? – 2012-07-20 14:46:58
http://bobby-tables.com/这是主要问题;) – haynar 2012-07-20 14:47:14
StackOverflow不是“这是我的代码,修复它”。你的代码在做什么?你得到什么错误?你有没有尝试过自己调试? – 2012-07-20 14:48:09