Forum Moderators: coopster
<?PHP
include("connect.php");
$link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not connect to database: '.mysql_error());
mysql_select_db($db_name,$link);
if(isset($_REQUEST['store']))
{
$description = $_POST['description'];
foreach($_POST['image'] as $key => $image) {
$query = mysql_query("INSERT INTO albums (image, description) VALUES ('{$image}','{$description}')");
}
}
mysql_close($link);
?>
<form action="formtest.php" method="post">
<input type="text" name="image[]" value="">Image1
<input type="text" name="image[]" value="">Image2<br>
<input type="text" name="description[]" value="">desc1
<input type="text" name="description[]" value="">desc2<br>
<input type="submit" name="store" value="Submit">
</form>
foreach($_POST['image'] as $key => $image) {
$query = mysql_query("INSERT INTO albums (image, description) VALUES ('{$image}','{$description[$key]}')");
}
foreach($_POST['image'] as $key => $image) {
$query = mysql_query("INSERT INTO albums (image, description) VALUES ('". mysql_real_escape_string($image)."','". mysql_real_escape_string($description[$key])."')");
}