Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving file path to Database / SQL
    primarykey
    data
    text
    <p>INTRO: I'm creating a 'Social network' site. It's more of a learning exercise than a business venture. I have created the simple version of login and registration (without encryption) they use PHPMyadmin and work.</p> <p>I've created a form to upload a picture (to later be displayed). The picture saves to the server, then i need to store the path to the db... but thats the bit where is all going wrong!!</p> <p>Every page includes "session_start();"</p> <p>Form:</p> <pre><code>&lt;form action="upload_ppl.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;br&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/form&gt; </code></pre> <p>upload_ppl.php:</p> <pre><code>&lt;?php session_start(); $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) &amp;&amp; ($_FILES["file"]["size"] &gt; 2000) &amp;&amp; in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] &gt; 0) { echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;"; } else { 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;"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $image_name= $FILES["file"]["name"]; $path=move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . rand().$_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; if(mysql_query("INSERT INTO *table* (*column*) VALUES ('$path')")){ echo "Successfull!!";} else { echo 'fail';} } } } else { echo "Invalid file"; } ?&gt; </code></pre> <p>Please note that on the 'connection.page' upon login the db connection is established! Do I need to carry this forward with a session variable, just create a new connection all together? I've tried tons. All suggestions appreciated. Thanks guys!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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