PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
not sure what you mean with the header function, but you may want to do a mysql_real_escape_string on the on the username and maybe md5 the password (or some other encryption method)
<?php
require 'DBConnect.php';
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT username, password FROM users WHERE username='$username'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if($username == $row['username'])
if($password == $row['password'])
echo "<h2>$username is logged in!<br>";
else
//I would like to redirect them back to the login page here!
echo "<h2>Incorrect username and/or password</h2>";
}
?>
Updated code I can now login correctly. see the comment about wanting to redirect. I cannot use Header( ) here.
Warning: Cannot modify header information - headers already sent by (output started at /home/whatith/public_html/Examples/DBConnect.php:10) in /home/whatith/public_html/Examples/login.php on line 18
james3302 wrote:
Updated code I can now login correctly. see the comment about wanting to redirect. I cannot use Header( ) here.
Warning: Cannot modify header information - headers already sent by (output started at /home/whatith/public_html/Examples/DBConnect.php:10) in /home/whatith/public_html/Examples/login.php on line 18
If you want to use the header function, you cant output anything, else headers will send automatically. so basically, you have to make sure you aren't echoing anything, and that's there isn't anything outside the php block being written.
okay so how would I do this then? Call another page and only have head('Location: Main.html'); in the file and that's it. How do I call another page? Wouldn't that be redirection too?
I just used java script to do it since PHP could not.
But now I have a control statement problem
When I enter the correct username and incorrect password it redirects me, but if I enter the incorrect username I do not get redirected. What's going on?