Hi,

I have created a php file to upload images i want this to store the image name in a mysql database.

I created this php code but when it comes to storing the file name in the database it stores each file name in a new row. Can anyone help me figure this out or point me in the right way.

Thanks alot heres the code!

<?php $conection = mysql_connect("localhost","enthuse1_user1","topiary1") 
or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db("enthuse1_uploadtest") or die('Cannot select database. ' . mysql_error()); ?>

<?php
$uploadNeed = $_POST['uploadNeed'];

for($x=0;$x<$uploadNeed;$x++){
	$file_name = $_FILES['ufile']['name'][$x];
	$file_name = stripslashes($file_name);
	$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['ufile']['tmp_name'][$x],"upload/".$file_name);
	$image[$x] = "$file_name";
	$column[$x] = "image$x";
 if($copy){
 $query = "INSERT INTO images ($column[$x]) VALUES ('$image[$x]');";
 mysql_query($query) or die('Error, insert query failed' . mysql_error());
 echo "$column[$x]<br>";	 
 echo "$image[$x] | uploaded sucessfully!<br>";
 	
 }else{
 echo "$image[$x] | could not be uploaded!<br>";
 }
} 
?>

Isn't that what you want? To store each file name in a new row?

How do you want to store the file names?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.