Note that there are some explanatory texts on larger screens.

plurals
  1. POerror in my PHP code
    text
    copied!<p>I'm getting an error in my code. If I put a wrong user, it shows </p> <blockquote> <p>user ok </p> </blockquote> <p>if I put correct user, it also shows</p> <blockquote> <p>user ok</p> </blockquote> <p>I don’t know where is the error in my code so please take a look at my code and let me know where I went wrong.</p> <p>Login.php</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form action="list_work.php" method="post"&gt; username: &lt;input type="text" name="username"&gt; password: &lt;input type="text" name="password"&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>List_work.php</p> <pre><code>&lt;?php $username = $_POST["username"]; $password = $_POST["password"]; // Connect to the database $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } mysqli_select_db($dbLink,"balhaf2"); // Fetch the file information $query = "select * from users WHERE username = '".$dbLink- &gt;escape_string($username)."'"; $result = $dbLink-&gt;query($query); $company = false; if($result) { echo "user ok"."&lt;/br&gt;"; //Now get the result information $row = $result-&gt;fetch_object(); //will store the record in $row //Access what you need if($row) { $company = $row-&gt;company; //variable name should match the field name in your database echo $company; //See if you get the value stored in the database } } else { echo "worng user"; } mysqli_select_db($dbLink,"balhaf"); // Query for a list of all existing files $sql = "SELECT id, name, mime, size, created FROM $company"; $result = $dbLink-&gt;query($sql); // Check if it was successfull if($result) { // Make sure there are some files in there if($result-&gt;num_rows == 0) { echo '&lt;p&gt;There are no files in the database&lt;/p&gt;'; } else { // Print the top of a table echo '&lt;table border="1" align="center"&gt; &lt;H2 align="center"&gt; Report Table&lt;/H&gt; &lt;tr&gt; &lt;td&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Mime&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Size (bytes)&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Created&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;'; // Print each file while($row = $result-&gt;fetch_assoc()) { echo " &lt;tr&gt; &lt;td&gt;{$row['name']}&lt;/td&gt; &lt;td&gt;{$row['mime']}&lt;/td&gt; &lt;td&gt;{$row['size']}&lt;/td&gt; &lt;td&gt;{$row['created']}&lt;/td&gt; &lt;td&gt;&lt;a style='text-decoration:none;' href='get_file_work.php?id= {$row['id']}&amp;company=$company'&gt;Download&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt;"; } // Close table echo '&lt;/table&gt;'; } // Free the result $result-&gt;free(); } else { echo 'Error! SQL query failed:'; echo "&lt;pre&gt;{$dbLink-&gt;error}&lt;/pre&gt;"; } // Close the mysql connection $dbLink-&gt;close(); ?&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