Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to include variables from one page in another when writing a file with fwrite()?
    text
    copied!<p>Here's the code:</p> <pre><code>&lt;?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 = $_POST['name']; $filename = $_POST['filename']; $submitter = $username; list($width, $height) = getimagesize("$filename"); $type = exif_imagetype($_POST['filename']); $checkuser = mysql_query("SELECT filename FROM images WHERE filename='$filename'"); $filename_exist = mysql_num_rows($checkuser); if($filename_exist &gt; 0){ echo "I'm sorry but this image has already been submitted. Please feel free to try another."; unset($filename); include 'upload.php'; exit(); } if (exif_imagetype($_POST['filename']) == IMAGETYPE_GIF) { echo "Sorry, but we can't accept GIFs. Please feel free to try uploading another."; unset($filename); include 'upload.php'; exit(); } $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(); echo "Thanks for your submission!&lt;br/&gt; Upload another &lt;a href='/~lyons/upload.php'&gt;here&lt;/a&gt;!"; $tpl = file_get_contents($tpl_path.$tpl_file); $php_file_name = $name.".php"; $fh = fopen($submissions_path.$php_file_name, "w"); fwrite($fh, $tpl); fclose($fp); ?&gt; </code></pre> <p>When a user submits a picture, it is supposed to automatically create a page based on a template. Here's the code for the template:</p> <pre><code>&lt;html&gt; &lt;title&gt;&lt;?php echo $name; ?&gt;&lt;/title&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;&lt;?php echo $name ?&gt;&lt;/h1&gt; Posted by: &lt;?php echo $username ?&gt; &lt;br/&gt; &lt;img src="&lt;?php echo $filename ?&gt;"/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>As you might have already guessed, I want it to put in values for name, username, and filename that were derived in the first script where they submit the picture. However, it seems they don't carry over. The page is created, but where ever it's supposed to echo the values for the variables, it is blank. <strong>How can I include the values for those variables that I want to use in the created page?</strong></p> <p>Thanks in advance to whoever can help me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload