Note that there are some explanatory texts on larger screens.

plurals
  1. POusing a form variable with a file upload script
    text
    copied!<p>I am using this form as a file upload form(as part of a larger php script, $pk is sanitized in the actual thing):</p> <pre><code>&lt;?php if (isset($_GET["pk"])) { $pk = $_GET["pk"];} echo '&lt;form action="up.php" method="post" enctype="multipart/form-data"&gt; &lt;label for="file"&gt;Filename:&lt;/label&gt; &lt;input type="file" name="file" id="file" /&gt; &lt;input type="hidden" name="pk" value="$pk"&gt; &lt;br /&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt;'; ?&gt; </code></pre> <p>I am using the following(extremely trimmed) code to handle the upload. Any syntax errors are a result of the tabifier I used.</p> <pre><code>&lt;?php if (isset($_GET["pk"])) { $pk = $_GET["pk"]; } $con = mysqli_connect("localhost","x","x", "x"); echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;"; echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;"; move_uploaded_file($_FILES["file"]["tmp_name"], "./" . $_FILES["file"]["name"]); echo "Stored in: " . "./" . $_FILES["file"]["name"]; $fileQuery = "INSERT INTO FILES VALUES (?, ?)"; if ($fileInsert = $con-&gt;prepare($fileQuery)) { $fileInsert-&gt;bind_param("ss", $pk, $_FILES["file"]["name"]); $fileInsert-&gt;execute(); $fileInsert-&gt;close(); } else { print_r($con-&gt;error); } ?&gt; </code></pre> <p>What I would like to know, is how do I access $pk. Is it already passed to the handling code with the form?</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