查询代码
$(document).ready(function () {
$("#add").click(function () {
$(".left .inputs").append("<li><input type ='text' name='name[]' class='txtbox1'></li>");
$(".right .inputs").append("<li><input type ='text' name='grade[]' class='txtbox'></li>");
});
});
我的 PHP 代码
<?php
$con = mysql_connect ("localhost","root","") or die('cannot connect to database error: '.mysql_error());
if (isset($_POST['name']) && isset($_POST['grade']))
{
$desk_report = $_POST['name'];//contains array value
$desk_action = $_POST['grade'];//contains array value
foreach($desk_report as $key=>$user) { //Loop through arrays
if (!empty($desk_report[$key]) && !empty($desk_action[$key])) {
mysql_select_db("quickbook", $con);
$sql = "INSERT INTO student_reg(relative_name,relative_grade) VALUES ('$desk_report[$key]','$desk_action[$key]')";
if ($sql_run = mysql_query($sql)) {
echo 'ok.';
} else {
echo '*Sorry, we couldn\'t register you at this time. Try again later.';
}
}
}
}
?>
我想将输入数据添加到数据库。我创建了一个代码。但这不起作用。你能帮帮我吗?