Jump to content

mutliple file upload and insert into DB -help


dflow

Recommended Posts

im doing smting basically wrong

 

<form action="" method="post">
<?php  
$x=1;
$images = $_GET['images'];
for( $i=0; $i<$images; $i++ )
{
  	echo '<input name="ID" type="hidden" value="1234" />
<br>
<input name="ImageURL['.$i.']" type="file"  value=""/><br><br>';
}

?>

<input name="submit" type="submit" />




<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_query("SET NAMES 'utf8'");
mysql_select_db("international", $con);

if (isset($_POST['submit']))
		for( $i=0; $i<$images; $i++ )
			{
$query=mysql_query("INSERT INTO images (ID,ImageURL) VALUES ('$_POST[iD]','$_POST[imageURL]')");

exit;



mysql_close($con);
} 

			 ?></form>

a bit more code

<form action="" method="post">
<?php  
$x=1;
$images = $_GET['images'];
for( $i=0; $i<$images; $i++ )
{
  	echo '<input name="ID" type="hidden" value="1234" />
<br>
<input name="ImageURL['.$i.']" type="file" value=""	/><br><br>';
}

?>

<input name="submit" type="submit" />




<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_query("SET NAMES 'utf8'");
mysql_select_db("international", $con);

if (isset($_POST['submit']))
		for( $i=0; $i<$images; $i++ )
			{
				// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['ImageURL['.$i.']']['name']); 

$query=mysql_query("INSERT INTO images (ID,ImageURL) VALUES ('$_POST[iD]','$_FILES')");

exit;



mysql_close($con);
} 
var_dump($_POST);

			 ?>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.