Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_POST not working. "Notice: Undefined index: username..."
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: “Notice: Undefined variable” and “Notice: Undefined index”</a> </p> </blockquote> <p>So, I am currently learning PHP and was reading on a book about the md5 function for passwords, so I decided to give it a try and see how it goes. I also decided to use the POST method rather than the GET, since I saw people saying that it is safer and doesn't let the variables appearing on the URL.</p> <p>For my testing project I made a very simple form, which follows:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="dologin" method="POST"&gt; &lt;table border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Username:&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="username"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password:&lt;/td&gt; &lt;td&gt;&lt;input type="password" name="password"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;input type="submit" value="Login"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The problem is that when I enter the values on BOTH fields and click "Login" I get the following output on the other PHP file.</p> <pre><code>Notice: Undefined index: username in C:\xampp\htdocs\md5\home\dologin\index.php on line 11 Username non existent </code></pre> <p>Here follows the code for the "/dologin/index.php" file</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $query = "SELECT password FROM users WHERE username='".$_POST['username']."'"; $result = mysql_query($query); $row = mysql_num_rows($result); if(isset($row)){ $password = (mysql_result($result,$row - 1)); $enteredpassword = md5("w@#$@#".$_GET['password']."^#3f%#^"); if($password == $enteredpassword){ if(!isset($_COOKIE['PHPSESSID'])){ session_start(); } $_SERVER['LOGIN_STATUS'] = true; } else { die("Access denied"); } } else { die("Username non existent"); } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Any help at all on my issue is very much appreciated, thank you for reading.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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