到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