你好!我想在我的数组中添加额外的 2 个 textarea 和一个下拉列表,它们将被插入到我的 mysql 数据库中。
我已经有一个 textarea 用于:
- 姓名
- 用户名
我想补充
- 密码
- 姓
- 组(这是一个下拉列表,我将从 mysql 中的组表中获取数据)
这是我到目前为止所得到的:
<?php
require_once "connect_to_mysql.php";
if($_POST['name'] || $_POST['username'])
{
$array=$_POST['name'];
$array2=$_POST['username'];
foreach ($array as $i => $name) {
$username = $array2[$i];
//$sql=mysql_query("insert into hobbies(hobby)values('$hobby')")
$sqlCommand = "INSERT INTO test(name, username) VALUES ('$name', '$username')";
$query = mysql_query($sqlCommand) or die (mysql_error());
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jquery Duplicate Fields Submit Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="reCopy.js"></script>
<script type="text/javascript">
$(function(){
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';
$('a.add').relCopy({ append: removeLink});
});
</script>
<style type="text/css">
body{ font-family:Arial, Helvetica, sans-serif; font-size:13px; }
.remove {color:#cc0000}
.input{ border: solid 1px #006699; padding:3px}
</style>
</head>
<body>
<div style="background-color:#ffffcc; padding:4px; border:#333 1px solid">9lessons programming Blog. Topics focused about jquery, ajax, mysql, php and java. <a href="http://9lessons.info">http://9lessons.info</a></div>
<form method="post" action="">
<p class="clone"> <input type="text" name="name[]" class='input'/>
<input type="text" name="lastname[]" class='input' id="lastname[]"/>
<input type="text" name="username[]" class='input' id="username[]"/>
<input type="text" name="password[]" class='input' id="password[]"/>
<?php
require_once "connect_to_mysql.php";
$part_id = $_SESSION['part_id'];
$query="SELECT * FROM groups WHERE part_id = '$part_id'";
$result = mysql_query($query);
echo '<select name="group" id="group">';
while($row=mysql_fetch_array($result)){
echo '<option value="' . $row['group'] . '">'. $row['group'] . '</option>';
}
echo '</select>';
?></p>
<p><a href="#" class="add" rel=".clone">Add More</a></p>
<input type="submit" value=" Submit " />
</form>
</body>
</html>