• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

How to make a preview page before submitting?

Ok so here is my image and other info php upload script. How do I preview this before the user submits it?
<?php 
session_start();
$error="";

//error_reporting(E_ALL); 


	// image upload folder
    $image_folder = 'images/classified/'; 
	// fieldnames in form
	$all_file_fields = array('image1', 'image2' ,'image3', 'image4');
	// allowed filetypes
	$file_types = array('jpg','gif','png','pdf');
	// max filesize 5mb
	$max_size = 5000000;
	//echo'<pre>';print_r($_FILES);exit;
	
	$time = time();
	$count = 1;
	
	foreach($all_file_fields as $fieldname){ 
		if($_FILES[$fieldname]['name'] != ''){
			
			$type = substr($_FILES[$fieldname]['name'], -3, 3);
						
			// check filetype
			if(in_array(strtolower($type), $file_types)){
				
				//check filesize
				if($_FILES[$fieldname]['size']>$max_size){
					$error = "File too big. Max filesize is ".$max_size." MB";
				
				}else{
				
					// new filename	
					$filename = str_replace(' ','',$myusername).'_'.$time.'_'.$count.'.'.$type;
			
					// move/upload file
					$target_path = $image_folder.basename($filename);
					move_uploaded_file($_FILES[$fieldname]['tmp_name'], $target_path);
				
					//save array with filenames
					$images[$count] = $image_folder.$filename;
					$count = $count+1;

				}//end if

			}else{ $error = "Please use jpg, gif, png or pdf files";
			
			}//end if
		}//end if
	}//end foreach



if($error != ''){ echo $error;	
}else{


/* --------------------------------------------------------------------------------------------------
SAVE TO DATABASE ------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------- */


$con = mysql_connect("localhost","","");
if (!$con){die('Could not connect: ' . mysql_error());}

// if residential
if($_POST['type'] == "residential"){
		mysql_select_db("", $con);
		$sql = "INSERT INTO apartments (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".$_POST['title']."', '".$_POST['county']."', '".$_POST['town']."', '".$_POST['type']."', '".$_POST['description']."','".$_POST['phone']."','".$_POST['rooms']."','".$_POST['bath']."','".$_POST['square']."','".$_POST['rent']."','".$_POST['fees']."','".$images[1]."','".$images[2]."','".$images[3]."','".$images[4]."')";

		$result = mysql_query($sql) or die(mysql_error());
}


// if commercial
else if($_POST['type'] == "commercial"){
		mysql_select_db("", $con);
		$sql = "INSERT INTO comm (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".$_POST['title']."', '".$_POST['county']."', '".$_POST['town']."', '".$_POST['type']."', '".$_POST['description']."','".$_POST['phone']."','".$_POST['rooms']."','".$_POST['bath']."','".$_POST['square']."','".$_POST['rent']."','".$_POST['fees']."','".$images[1]."','".$images[2]."','".$images[3]."','".$images[4]."')";

		$result = mysql_query($sql) or die(mysql_error());
}


	echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br /><h1>You Have Successfully Posted</h1>";
	echo "<p>&nbsp;</p><p>&nbsp;</p><br /><a href='index.php'>go to your ACCOUNT page</a>";

	
}//end if		
	
	?>

Open in new window

0
genesisvh
Asked:
genesisvh
1 Solution
 
h2g2guyCommented:
PDF's would probably be really tricky to preview, unless you want to use frames...and I HATE frames...

The way I'd do a confirmation page for photos, at least, would just be to create another two pages.  First of all, the page that you already have will save the photos to a temporary location, without updating any databases.  When you submit the page, it will lead to the first new page which will be a simple yes or no, 'is this the right information' page.  If you hit yes on that page, it'll lead to the second new page.  THIS page will be the one that saves the pictures in a more permanent location, as well as saving all the information to the database.  
0
 
genesisvhAuthor Commented:
To be honest all I want is the text to be previewed. Not to concern with the images since the user will be able to change them later if he/her chooses so.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now