Input text and image upload in ajax

I tried to echo the value of my ID (assuming I’ve got the value ) it seems like there’s no place to echo it in my page, I am thinking to append my ID value to the result message ''Photo uploaded successfully" how can I do that? I tried also to append my ID value in the name of my photo


$id  = $_GET['ID'];

$uploaddir = '../upload/';
$file = $uploaddir ."student_".basename($_FILES['uploadfile']['name']);
$file_name = "student_".$id."_".$_FILES['uploadfile']['name'];

but it doesnt change.
I think I should have tried to find another work around in my js.

Just so we’re on the same page, here’s my understanding of what happens:

  1. The user goes to a page on your website (let’s call it “Page A”).
  2. On this page, they upload a file.
  3. You have that AjaxUpload script that starts the upload immediately.
  4. The file is uploaded to “stud_image_act.php” (let’s call this “Page B”), which validates the file and (if it’s okay) moves it to the appropriate folder.
  5. Note: The user never actually visits Page B; this is all done with AJAX while the user waits patiently at Page A.
  6. After the file upload is completed, Page B generates an ID for the file.
  7. You now want to add this ID to the database.

Does that sound right?

If yes, then your PHP already has the ID, and can add it to the database; there’s no need to get JavaScript involved at all.

You got it all friend, that is exactly my problem now. I tried all things I know to find out the real issue. And you got it all right. Perhaps I need to make sure that I’ve got already the value of my ID. This is the way I save my ID in DB.


echo $id = $_GET['ID'];
	
$uploaddir = '../upload/';
$file = $uploaddir ."student_".basename($_FILES['uploadfile']['name']);
$file_name = "student_".$id."_".$_FILES['uploadfile']['name'];

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file))
	{
	mysql_query("UPDATE tbl_student
				    SET stud_Image= '$file_name'
				  WHERE id = '$id'"	) or die (mysql_error());
	echo "success";
	} else {
	echo "error";
	
}

Where is the ID coming from? How are you generating it?

the original value of ID came from my other page then I sent it to my stud_image.php. I am sure that the value is in the page because I can echo it. Since the processing is in the stud_image_act.php I tend to hide it hidden text to send it to my action via ajax. In that sense I can save it to my database now.