Hi everyone, well, I am working on the login section of my site and it doesn't seem to want to do anything. I have it checking the entered info against a database, but it doesn't matter if I enter valid data or just junk, the page doesn't do anything, it just reloads when I try to submit the form. Here is the php code:
if (isset($_POST['submit']) && $_POST['submit'] == "Login") {
if ($username != " " && $hashpw != " ") {
$query = "SELECT user_name FROM login_info WHERE user_name = '$username';";
$query2 = "SELECT password FROM login_info WHERE password = '$hashpw';";
$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
if (mysql_num_rows($result) != 0 && mysql_num_rows($result2) != 0) {
header('Location: http://www.fakedomain.com/upload.php');
}
else {
print "<p><span style='color:#CC0000'>The Username and Password you entered does not exist.</span><br/>";
print "You can contact us at <a href='mailto:someone@fake.com'>Customer Service</a> if you need help with your account.";
}
}
}
?>
Anyone feel like offering some input on this? Like, what could be causing my page to just reload rather than redirect to the appropriate page or display the error message?
$query = "SELECT user_name FROM login_info WHERE user_name = '$username';";
$query2 = "SELECT password FROM login_info WHERE password = '$hashpw';";
$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
if (mysql_num_rows($result) != 0 && mysql_num_rows($result2) != 0) {
combine the SQL statement and use:
PHP Code:
$query = "SELECT user_name FROM login_info WHERE user_name = '$username' AND password = '$hashpw' LIMIT 1;";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) != 0) {
That should take care of the untimely redirect as well.
I was just reading through the MySQL manual and was about to go give that a try to prevent just any combination from letting anyone in. What about the page just reloading though, will that fix that also?
Ok, well I am still just getting the page to reload, when I click the login button for my form it just seems to reload the page. The data is being submitted but it is not sending the header request it seems like. Does the header have to be before the <html> tags to work?
No, not really, I was just trying to say "if the string is not empty", ergo, it has content, redirect to the address in the header(). I changed to the <> "", but I don't see what that does exactly and I am still just getting the page to reload. Here are the changes I have made to the script so far:
PHP Code:
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Login") {
print "Username: " .$username;
print "Password: " .$password;
print "The password we are comparing: " .$hashpw;
if ($username <> "" && $hashpw <> "") {
$query = "SELECT user_name FROM login_info WHERE user_name = '$username' AND password = '$hashpw' LIMIT 1;";
$result = mysql_query($query) or die(mysql_error());
print "This is the result of the query: " .$result;
if (mysql_num_rows($result) != 0) {
header('Location: http://www.fake.com/upload.php');
exit();
}
else {
print "<p><span style='color:#CC0000'>The Username and Password you entered does not exist.</span><br/>";
print "You can contact us at <a href='mailto:someone@fake.com'>Customer Service</a> if you need help with your account.";
}
}
}
?>
I put the variables inside the if statement becuase when they were outside it they were being assigned random values before the form was even submitted.
Though, now nothing is being printed to the screen, so the script isn't even getting into the if statement. I don't see why it wouldn't though.
Bookmarks