URL parameter get disappear

I pass the id as an URL param, but when I submit the form id get disappearis there anyway to keep it when page get refresh ?
<?php 
$_GET['id'];
		
$new_id = 'img'.$_GET['id'];

echo $new_id ;
						
$upload_errors = array(

	UPLOAD_ERR_OK 				=> "No errors.",
	UPLOAD_ERR_INI_SIZE  	=> "Larger than upload_max_filesize.",
  UPLOAD_ERR_FORM_SIZE 	=> "Larger than form MAX_FILE_SIZE.",
  UPLOAD_ERR_PARTIAL 		=> "Partial upload.",
  UPLOAD_ERR_NO_FILE 		=> "No file.",
  UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
  UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
  UPLOAD_ERR_EXTENSION 	=> "File upload stopped by extension."
);




if(isset($_POST['subtrue'])==1){
	
        if(isset($_POST['submit'])){
		$a=($_FILES["file_upload"]);
		$jpage= $a['type'];	
		$tmp_file=$_FILES['file_upload']['tmp_name'];
		$target_file=basename($_FILES['file_upload']['name']);
		$upload_dir='thumbs';
		//if(move_uploaded_file($tmp_file,$uplaod_dir,'/'.$target_file))
	if($jpage=='image/jpeg'||$jpage=='image/pjpeg'){
	
		if(move_uploaded_file($tmp_file, $upload_dir."/"."$new_id.jpg")) {
		
		medium($new_id);	
		
		
	$picview="$new_id.jpg";
		$message="File uploaded successfully";
	
		}//end move if

		else{

		$error = $_FILES['file_upload']['error'];
		$message = $upload_errors[$error];
		}//end else move
		
	}//end of if jpeg
	else{
		$message="You can uplod only JPEG File ...";
	}//end else Jpeg

}// end of post submit 
		
		
						
					
				
	 }//end of !pho
	 else
	 { 
	  $pho_error="Pleas Enter Photo Title"; 
	 	
	 }//end of else
	
	




?>

Open in new window

sahanlakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

04it040Commented:
Modify following line to get mysql error if any..


This will give you a fair idea about the problem.
$add_member = mysql_query($insert) or die(mysql_error());

Open in new window

0
04it040Commented:
Ignore my last comment....

its for some other question...

Sorry of inconvenience caused.
0
Cornelia YoderArtistCommented:
What do you mean disappears?   Do you mean that when you do

$inputid = $_GET['id'];
echo $inputid;

that the echo shows nothing?
                 

By the way, you should ALWAYS check ALL inputs for safety.  For example, if id is an integer:

$inputid = floor($_GET["id"]);  will ensure that it is an integer, and not some SQL Injection hacking.

Once you have a safe $inputid, then

$new_id = 'img'.$inputid;  
echo $new_id ;
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

sahanlakAuthor Commented:
I call this page like this, upload.php?id=2 so when uploading I want the image to be renamed img2.jpg

So when I load the page :-
$_GET['id'];
$new_id = 'img'.$_GET['id'];
 -------------

When I call the page upload.php?id=2 , $new_id = "img2". But when I hit the upload button the page gets refreshed and that time it's not calling any id so I'm getting only "img"

so all I want is to pass the id for $new_id whil page get refreshed.

See the complete code for the page
<?php 
$_GET['id'];
		
$new_id = 'img'.$_GET['id'];

echo $new_id ;
						
$upload_errors = array(

	UPLOAD_ERR_OK 				=> "No errors.",
	UPLOAD_ERR_INI_SIZE  	=> "Larger than upload_max_filesize.",
  UPLOAD_ERR_FORM_SIZE 	=> "Larger than form MAX_FILE_SIZE.",
  UPLOAD_ERR_PARTIAL 		=> "Partial upload.",
  UPLOAD_ERR_NO_FILE 		=> "No file.",
  UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
  UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
  UPLOAD_ERR_EXTENSION 	=> "File upload stopped by extension."
);




if(isset($_POST['subtrue'])==1){
	
        if(isset($_POST['submit'])){
		$a=($_FILES["file_upload"]);
		$jpage= $a['type'];	
		$tmp_file=$_FILES['file_upload']['tmp_name'];
		$target_file=basename($_FILES['file_upload']['name']);
		$upload_dir='thumbs';
		//if(move_uploaded_file($tmp_file,$uplaod_dir,'/'.$target_file))
	if($jpage=='image/jpeg'||$jpage=='image/pjpeg'){
	
		if(move_uploaded_file($tmp_file, $upload_dir."/"."$new_id.jpg")) {
		
		medium($new_id);	
		
		
	$picview="$new_id.jpg";
		$message="File uploaded successfully";
	
		}//end move if

		else{

		$error = $_FILES['file_upload']['error'];
		$message = $upload_errors[$error];
		}//end else move
		
	}//end of if jpeg
	else{
		$message="You can uplod only JPEG File ...";
	}//end else Jpeg

}// end of post submit 
		
		
						
					
				
	 }//end of !pho
	 else
	 { 
	  $pho_error="Pleas Enter Photo Title"; 
	 	
	 }//end of else
	
	




?>
<html>

<head>
</head>
<body>



	<form action="upload.php" enctype="multipart/form-data" method="post">
    <table>
	<tr><td>Picture Upload
	<input type="hidden" name="MAX_FILE_SIZE" value="1000000"></input>
	<td><input type="file" name="file_upload"></input></td>
	<input type="hidden" name="subtrue" value="1"></input></td>
	<td><input type="submit" name="submit" value="Upload"></input></td>
	</tr>
	</table>
</form>
 <?php if(!empty($message)) 
{
echo "<p> {$message} </p>";

}
?>
<?php 

if(!empty($picview)){

echo " <img src='thumbs/medium/$picview'/>";

}
?>



</body>

</html>
<?php


function medium($new_id)
 {
   
		$img = 'thumbs/'.$new_id.'.jpg';
		$canvas_width  = 80;
		$canvas_height = 80;
		list($img_width, $img_height) = getimagesize($img);
		
		$ratio_orig = $img_width / $img_height;
		
		if($canvas_width / $canvas_height > $ratio_orig)
		{
		  $canvas_width = $canvas_height * $ratio_orig;	
		}
		else
		{
			$canvas_height = $canvas_width / $ratio_orig;
		}
		
		$original = imagecreatefromjpeg($img);
		
		$canvas = imagecreatetruecolor($canvas_width, $canvas_height);
		
     imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height);
		
		if(imagejpeg($canvas, 'thumbs/medium/'.$new_id.'.jpg', 80))
		{
		   return true	;
		}
		else
		{
		   return false;	
		}
 }

?>

Open in new window

0
04it040Commented:
change action of the from to :-

upload.php?id=<?php echo $_GET['id']; ?>


like :-


<form action="upload.php?id=<?php echo $_GET['id']; ?>" enctype="multipart/form-data" method="post">

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sahanlakAuthor Commented:
@04it040

Hey man your awesome. I din't thought of that. Let me try it :)
0
sahanlakAuthor Commented:
Simple trick, worth more  than the rating. Thanks again
0
04it040Commented:
Hi sahanlak,

Thanks for the points  :)


Regards,
Abhinav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.