Question

I have an image submission form that just uses a simple action="" to get to a PHP page that adds the submission details to the DB and creates a unique page for the submission. That works fine. However, I want it to redirect to their submission page (created with fwrite()) How would I do this? Code below.

<?php
// For use in creating individual page
$tpl_file = "submission.php";
$tpl_path = "templates/";
$submissions_path = "submissions/";



// For use in querying submitter name

$username = $_GET['username'];
session_start();
$_SESSION['username'] = $username; 

//Database Information

   $dbhost = ""; 
   $dbname = ""; 
   $dbuser = ""; 
   $dbpass = ""; 

//Connect to database

mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$name = $_GET['right_form_title'];
$filename = $_GET['right_form_url'];   
$submitter = $username;
$type = exif_imagetype($_GET['right_form_url']);

list($width, $height) = getimagesize($filename);

$query = "INSERT INTO images (name, filename, submitter, width, height, type)
VALUES('$name', '$filename', '$submitter', '$width', '$height', $type)";
mysql_query($query) or die(mysql_error());
mysql_close();

$php_file_name = $name.".php";
$path_for_link = $submissions_path.$php_file_name;


$tpl = file_get_contents($tpl_path.$tpl_file);
$tpl_and_values = preg_replace("(%([a-z_][a-z0-9_]*)%)ie",'$$1',$tpl);

$fh = fopen($submissions_path.$php_file_name, "w");
fwrite($fh, $tpl_and_values);
fclose($fh); 

?>
Was it helpful?

Solution

Adding this after you close the file would work just fine.

header('location: '.$submissions_path.$php_file_name);

OTHER TIPS

I believe all you need to do is stick a header at the bottom of that file which will redirect to the newly created file. Try adding this at the bottom of your file.

header('Location: '.$submissions_path.$php_file_name);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top