试图在数据库中插入多个输入值但只插入一个表..请检查并帮助。谢谢
<form action="insert.php" method="post" id="database" name="database" >
<?php
foreach($_POST['url_link'] as $value)
{
echo '<input type="text" name="url_db[]" size="150" value="'.$value.'"/><br />';
}
?>
<br><hr>Categories:<select name="cat" id="cat">
<option value="Mobile">Mobile
<option value="T-Shirt">T-Shirt
</select>
Website:<input type="text" size="50" value="" name="web" id="web"/><input type="submit" value="Save to DB>>" name="datasub"/>
</form>
插入.php -
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$count = count($_POST['url_db']);
if (isset($_POST['url_db'])) {
for($i=0;$i<$count;$i++){
$urllink = $_POST['url_db'][$i];
$web = $_POST['web'];
$cat = $_POST['cat'];
$sql="INSERT INTO $tbl_name (web, urllink, cat) VALUES ('$web', '$urllink', '$cat')";
if(!($result = mysql_query($sql))){
"<BR>Error Adding!!<BR>".mysql_error();
exit();
}
header("location:index.php");
}
}
?>
有关信息 - 我正在尝试使用带有类别名称(下拉列表)和网站名称的输入框插入多个 url 链接。url_db[]-
<form action="insert.php" method="post" id="database" name="database">
<input type="text" name="url_db[]" size="150" value="http://www.google.dk/imghp?hl=da&tab=wi"><br>
<input type="text" name="url_db[]" size="150" value="http://maps.google.dk/maps?hl=da&tab=wl"><br>
<input type="text" name="url_db[]" size="150" value="https://play.google.com/?hl=da&tab=w8"><br>
<input type="text" name="url_db[]" size="150" value="http://www.youtube.com/?gl=DK&tab=w1"><br>
<input type="text" name="url_db[]" size="150" value="https://mail.google.com/mail/?tab=wm"><br><br>
<hr>Categories:<select name="cat" id="cat">
<option value="Mobile">Mobile
</option><option value="T-Shirt">T-Shirt
</option></select>