943,097 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 589
  • PHP RSS
Feb 5th, 2010
0

Login Script

Expand Post »
Ok, so l am new to php ... sort of, now l have managed to throw this together:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $con = mysql_connect("localhost","root","");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8.  
  9. mysql_select_db("test_database", $con);
  10.  
  11. if(isset($_POST['Login']))
  12. {
  13. if($_POST['username']!='' && $_POST['password']!='')
  14. {
  15. //Use the input username and password and check against 'users' table
  16. $query = mysql_query('SELECT ID, username, Active FROM persons WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');
  17.  
  18. if(mysql_num_rows($query) == 1)
  19. {
  20. $row = mysql_fetch_assoc($query);
  21. if($row['Active'] == 1)
  22. {
  23. $_SESSION['user_id'] = $row['ID'];
  24. $_SESSION['logged_in'] = TRUE;
  25. header("Location: members.php");
  26. }
  27. else {
  28. $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
  29. }
  30. }
  31. else {
  32. $error = 'Login failed !';
  33. }
  34. }
  35. else {
  36. $error = 'Please enter both your username and password to access your account';
  37. }
  38. }
  39. ?>

Here is my html:
PHP Syntax (Toggle Plain Text)
  1. <form action="login.php" method="get">
  2. Username: <input type="text" name="username" /> <br>
  3. Password: <input type="password" name="password" /> <br><br>
  4. <input type="submit" value="Login" />
  5. <input type="reset" value="Reset" /> <br>
  6. </form>

Now, this is not working, when l try it it displays a blank white page, anyone know what l have done wrong?
Similar Threads
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
dlannetts is offline Offline
83 posts
since Jan 2010
Feb 5th, 2010
1
Re: Login Script
PHP Syntax (Toggle Plain Text)
  1. ob_start();
  2. session_start();
fix above code at top of page
and replace
PHP Syntax (Toggle Plain Text)
  1. mysql_fetch_assoc($query);
with
PHP Syntax (Toggle Plain Text)
  1. mysql_fetch_array($query);
and in form
PHP Syntax (Toggle Plain Text)
  1. <form action="login.php" method="post">
replace method="get" with method="post " as like above.
try it .
Reputation Points: 12
Solved Threads: 27
Junior Poster
rajabhaskar525 is offline Offline
179 posts
since Nov 2009
Feb 5th, 2010
0
Re: Login Script
mmm, this didn't work, still displays a white page, due to my script it should open the file members.php if it logged in successfully shouldn't it? before it was adding extra stuff into my url bar too, what you have done has gotten rid of that, so that is good l guess...

Added a picture of the wampserver screen db, click image for larger view...
Attached Thumbnails
Click image for larger version

Name:	WampServer.JPG
Views:	16
Size:	15.7 KB
ID:	13517  
Last edited by dlannetts; Feb 5th, 2010 at 7:09 am.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
dlannetts is offline Offline
83 posts
since Jan 2010
Feb 5th, 2010
1
Re: Login Script
Does your page members.php have some code that checks the session variable is set? If so can you post that code?
Reputation Points: 14
Solved Threads: 12
Junior Poster in Training
Hangfire is offline Offline
62 posts
since Mar 2009
Feb 5th, 2010
1
Re: Login Script
and also
PHP Syntax (Toggle Plain Text)
  1. <input type="submit" name="Login"value="Login" />
fix it. you forgot to write name="Login" in submit botton.
Reputation Points: 12
Solved Threads: 27
Junior Poster
rajabhaskar525 is offline Offline
179 posts
since Nov 2009
Feb 6th, 2010
0
Re: Login Script
and also
PHP Syntax (Toggle Plain Text)
  1. <input type="submit" name="Login"value="Login" />
fix it. you forgot to write name="Login" in submit botton.
Yep, done this, forgot about that, this is my members.php file:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. session_start();
  4.  
  5. ?>
  6.  
  7. <html>
  8. <body>
  9. help...

AZnythiong wrong here? thanks for everyones help so far, yous have been great...
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
dlannetts is offline Offline
83 posts
since Jan 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to create a link in php
Next Thread in PHP Forum Timeline: easy url variable example please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC