2 Replies - 472 Views - Last Post: 01 April 2012 - 11:31 AM Rate Topic: -----

#1 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

why is my login not working ? :(

Posted 01 April 2012 - 07:56 AM

hey there this should have been really easy to code for me but for some reason i can't get my login to work(its not for an actual site)

if (isset($username,$password)) {
	$pre_sql = "SELECT * FROM users WHERE username='{$username}' AND password='{$password}'";
	$sql = mysql_query($pre_sql);
	$final = mysql_num_rows($sql);
}

if(isset($final) && $final == 1){
	header('Location: index.html')
}
else {
	die("invalid username,password");
}



im not getting redirected to index.html and im not getting the invalid username,password either :S

Is This A Good Question/Topic? 0
  • +

Replies To: why is my login not working ? :(

#2 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: why is my login not working ? :(

Posted 01 April 2012 - 08:18 AM

Hi!

It seems easy enough, but you might want to consider the following:

1. You don't need the curly brackets in your SQL query.
2. Are you getting any error messages?
3. Are you actually connected to the database?

You can test the database connection by echoing the data you're requesting:
if (isset($username,$password)) {
	$pre_sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
	$sql = mysql_query($pre_sql) or die(mysql_error());
	while($final = mysql_fetch_assoc($sql)){
            echo $final['username'];
            echo $final['password'];
        }
}



If that produces no result, you may not be connected to your SQL database at all!

- Cbeppe

This post has been edited by Cbeppe: 01 April 2012 - 08:20 AM

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: why is my login not working ? :(

Posted 01 April 2012 - 11:31 AM

4. it also doesn’t redirect if there is output before the header() call.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1