Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay option to delete files if user type is correct
    text
    copied!<p>I have a simple file-sharing page that allows the user to upload images and display the directory contents in a list. I have 2 users in my Database, an I want to make it so only one can delete files. My database has a type column for the users and these values are 1 or 2. Here is my code:</p> <pre><code> &lt;body&gt; &lt;?php include "view/header.php" ?&gt; &lt;div id="main"&gt; &lt;h2&gt;Image to be uploaded&lt;/h2&gt; &lt;form id="upload_form" action="." method="POST" enctype="multipart/form-data"&gt; &lt;input type="hidden" name="action" value="upload"&gt; &lt;input type="file" name="file1"&gt;&lt;br /&gt; &lt;input id="upload_button" type="submit" value="Upload"&gt; &lt;/form&gt; &lt;h2&gt;Images in the directory&lt;/h2&gt; &lt;?php if (count($files) == 0) : ?&gt; &lt;p&gt;No images have been uploaded.&lt;/p&gt; &lt;?php else: ?&gt; &lt;ul&gt; &lt;?php foreach($files as $filename) : $file_url= $image_dir . '/' . $filename; $delete_url= '.?action=delete&amp;filename=' . urlencode($filename); ?&gt; &lt;li&gt; &lt;a href= "&lt;?php echo $delete_url;?&gt;"&gt; &lt;img src= "images/delete.png" alt= "Delete"&gt;&lt;/a&gt; &lt;a href= "&lt;?php echo $file_url;?&gt;"&gt; &lt;?php echo $filename;?&gt;&lt;/a&gt; &lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;div id="footerholder"&gt; &lt;div id="footer"&gt; &lt;?php include "view/footer.php" ?&gt; &lt;/div&gt; </code></pre> <p> </p> <p>This is what my login page refers to:</p> <pre><code>&lt;?php $dsn= 'mysql:host=localhost; dbname=file_share'; $username= 'root'; $password= ''; try { $db= new PDO($dsn, $username, $password); } catch (PDOException $e) { $error_message= $e-&gt;getMessage(); echo "&lt;p&gt;An error occured while connecting to the database: $error_message &lt;/p&gt;"; } //Only run code below if form has been posted if($_SERVER['REQUEST_METHOD'] == 'POST') { if( isset($_POST['username'], $_POST['password']) &amp;&amp; !empty($_POST['username']) &amp;&amp; !empty($_POST['password']) ) { $username = $_POST['username']; $password = $_POST['password']; $sql= 'SELECT * FROM `users` WHERE `username` = :username AND `password` = :password LIMIT 1'; //SQL query with named placeholders $stmt = $db-&gt;prepare($sql); //Returns a PDOStatement class object $stmt-&gt;bindParam(':username',$username,PDO::PARAM_STR,16); $stmt-&gt;bindParam(':password',$password,PDO::PARAM_STR,16); $stmt-&gt;execute(); $result = $stmt-&gt;fetch(PDO::FETCH_ASSOC); $error = $stmt-&gt;errorInfo();//Debug if($error[0] != '00000') printf('SQL Error: &lt;pre&gt;%s&lt;/pre&gt;', print_r($error, true)); if($stmt-&gt;rowCount() &gt; 0) { $_SESSION['loggedIn']= "true"; header("Location: uploader.php"); } else { echo 'Sorry username/password wrong'; echo '&lt;br&gt;&lt;a href="login.php"&gt;Try Again&lt;/a&gt;&lt;/br&gt;'; } </code></pre>
 

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