Jump to content

Recommended Posts

Dear all friends

 

I look hardly into a lot of topics and images, and its always ends up with not solved or a not good code that would suites my options.

 

what I want is a code to upload multiple images and store them into a folder called upload and also the name of the folder will be inside a table in mysql called image_img.

 

NOW I have done this code but only with uploading one image!.

 

and thats the code i used

 

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO packages (idd, packageTitle, packageDescription, packageGraphic) VALUES (%s, %s, %s, %s)",

      GetSQLValueString($_SESSION['MM_adminId'], "text"),

  GetSQLValueString($_POST['packageTitle'], "text"),

                      GetSQLValueString($_POST['packageDescription'], "text"),

                      GetSQLValueString($_FILES['packageGraphic']['name'], "text"));

 

 

 

  mysql_select_db($database_dalilack, $dalilack);

  $Result1 = mysql_query($insertSQL, $dalilack) or die(mysql_error());

 

$target_path = "upload/".$_FILES['packageGraphic']['name'];

move_uploaded_file($_FILES['packageGraphic']['tmp_name'],$target_path);

 

  $insertGoTo = "marketList.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

 

 

and just for your information this "idd" is to connect to each user personal information.

so when uploading photos, it should be only connected for one user.

 

so when display data. it will be like a dynamic table with his personal info and his images also.

 

And that's kind of coding i couldn't solve and find in Google.

 

So I am here hoping to be served and helped by you guys.

 

Thank you so much

Link to comment
https://forums.phpfreaks.com/topic/264216-upload-multiple-images-to-mysql/
Share on other sites

  • 4 weeks later...

ok I have did some updates and add a code where you can upload more images

<script type="text/javascript">
$(document).ready(function(){
	$('#addFileInput').click(function(){
		$('#packageGraphicDiv').html($('#packageGraphicDiv').html() + '<p><input type="file" name="packageGraphic[]" id="upload"  value="" size="32" /></p>');

		return false;
	});
});
</script>

 

and then I have add 

 

  $insertSQL = sprintf("INSERT INTO packages (idd, packageTitle, packageDescription, packageGraphic, packageGraphic2) VALUES (%s, %s, %s, %s, %s)",

 

 

GetSQLValueString($_FILES['packageGraphic']['name'], "text"),

  GetSQLValueString($_FILES['packageGraphic2']['name'], "text"));

 

and then these

$target_path = "upload/".$_FILES['packageGraphic']['name'];

move_uploaded_file($_FILES['packageGraphic']['tmp_name'],$target_path);

 

$target_path = "upload/".$_FILES['packageGraphic2']['name2'];

move_uploaded_file($_FILES['packageGraphic2']['tmp_name'],$target_path);

 

and i am still getting an error! saying Column 'packageGraphic' cannot be null

 

mysql_real_escape_string() expects parameter 1 to be string

 

Undefined index: packageGraphic2

 

 

whats the problem?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.