User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 428,629 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,963 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1790 | Replies: 21 | Solved
Reply
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 175
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help login form and MySQL connection/validation error

  #1  
Feb 6th, 2008
  1. <?php
  2. // connection to MySQL server
  3. mysql_connect('localhost','root','root');
  4. mysql_select_db('administration');
  5.  
  6. // *** Validate request to login to this site.
  7. //session_start();
  8.  
  9. $loginFormAction = $_SERVER['PHP_SELF'];
  10. if (isset($accesscheck)) {
  11. $GLOBALS['PrevUrl'] = $accesscheck;
  12. session_register('PrevUrl');
  13. }
  14.  
  15. if (isset($_POST['username'])) {
  16. $loginUsername=$_POST['username'];
  17. $password=$_POST['password'];
  18. //$MM_fldUserAuthorization = "level_usr";
  19. $MM_redirectLoginSuccess = "validated.php";
  20. $MM_redirectLoginFailed = "index.html";
  21. $MM_redirecttoReferrer = true;
  22. //mysql_select_db($database_connBlog, $connBlog);
  23. mysql_select_db($database, $administration);
  24.  
  25. $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  26. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  27. $LoginRS = mysql_query($LoginRS__query, $adminprofile) or die(mysql_error());
  28. $loginFoundUser = mysql_num_rows($LoginRS);
  29. if ($loginFoundUser) {
  30.  
  31. // $loginStrGroup = mysql_result($LoginRS,0,'level_usr');
  32.  
  33. //declare two session variables and assign them
  34. // $GLOBALS['MM_Username'] = $loginUsername;
  35. //$GLOBALS['MM_UserGroup'] = $loginStrGroup;
  36.  
  37. //register the session variables
  38. //session_register("MM_Username");
  39. //session_register("MM_UserGroup");
  40.  
  41. if (isset($_SESSION['PrevUrl']) && true) {
  42. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  43. }
  44. header("Location: " . $MM_redirectLoginSuccess );
  45. }
  46. else {
  47. header("Location: ". $MM_redirectLoginFailed );
  48. }
  49. }
  50. ?>

errors:
1.Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\cycle\validate.php on line 34

2.Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\cycle\validate.php on line 38


Please help as I couldn't make the code to check my username and password from the login page and validate it with the information stored in the database.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: login form and MySQL connection/validation error

  #2  
Feb 6th, 2008
On line 23, mysql_select_db($database, $administration); What are you trying to do ?
If administration is the database name, you should give, mysql_select_db('administration');
Read more on mysql_select_db here.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 175
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: login form and MySQL connection/validation error

  #3  
Feb 6th, 2008
Thank you nav33. I did not noticed it. But even though I've amend it, the 2nd error was still there. Kindly help. $adminprofile is the table inside database 'administration'
Last edited by lordx78 : Feb 6th, 2008 at 9:56 am.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: login form and MySQL connection/validation error

  #4  
Feb 6th, 2008
You dont need $adminprofile. mysql_query takes 2 parameters. 1. The query and 2. The connection resource. The second one is optional.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 175
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: login form and MySQL connection/validation error

  #5  
Feb 6th, 2008
yes i managed to identify the errors, but now the problem is at line "44". It doesn't redirect me? any of the syntaxes wrong? I'm really sorry if I'm asking too much. I'm new to this language.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: login form and MySQL connection/validation error

  #6  
Feb 6th, 2008
The syntax isnt wrong. Print whats in $MM_redirectLoginSuccess and $MM_redirectLoginFailed. Header function fails if you are outputting ANYTHING before calling a header function.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 175
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help Re: login form and MySQL connection/validation error

  #7  
Feb 6th, 2008
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <title>Cycle Tracks Portal - Validation Page</title>
  6. <style type="text/css" media="all">@import "images/style.css";
  7. </style>
  8. <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. // connection to MySQL server
  14. mysql_connect('localhost','root','root');
  15. mysql_select_db('administration');
  16.  
  17. // *** Validate request to login to this site.
  18. //session_start();
  19.  
  20. if (isset($_POST['username'])) {
  21. $loginUsername=$_POST['username'];
  22. $password=$_POST['password'];
  23. $MM_redirectLoginSuccess = "validate.php";
  24. $MM_redirectLoginFailed = "index.html;
  25. $MM_redirecttoReferrer = true;
  26. mysql_select_db('administration');
  27.  
  28. $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  29. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  30. $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  31. $loginFoundUser = mysql_num_rows($LoginRS);
  32. if ($loginFoundUser) {
  33.  
  34. header("Location: " . $MM_redirectLoginSuccess );
  35. }
  36. else {
  37. header("Location: ". $MM_redirectLoginFailed );
  38. }
  39. ?>
  40.  
  41. </body>
  42. </html>
  43.  

This my new set of codes. now the error at line "28".It says that,

"Parse error: syntax error, unexpected T_STRING in D:\xampp\htdocs\cycle\validate.php on line 28"
Last edited by lordx78 : Feb 6th, 2008 at 11:14 am.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: login form and MySQL connection/validation error

  #8  
Feb 6th, 2008
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <title>Cycle Tracks Portal - Validation Page</title>
  6. <style type="text/css" media="all">@import "images/style.css";
  7. </style>
  8. <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. // connection to MySQL server
  14. mysql_connect('localhost','root','root');
  15. mysql_select_db('administration');
  16.  
  17. // *** Validate request to login to this site.
  18. //session_start();
  19.  
  20. if (isset($_POST['username'])) {
  21. $loginUsername=$_POST['username'];
  22. $password=$_POST['password'];
  23. $MM_redirectLoginSuccess = "validate.php";
  24. $MM_redirectLoginFailed = "index.html";
  25. $MM_redirecttoReferrer = true;
  26. mysql_select_db('administration');
  27.  
  28. $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  29. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  30. $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  31. $loginFoundUser = mysql_num_rows($LoginRS);
  32. if ($loginFoundUser) {
  33.  
  34. header("Location: " . $MM_redirectLoginSuccess );
  35. }
  36. else {
  37. header("Location: ". $MM_redirectLoginFailed );
  38. }
  39. ?>
  40.  
  41. </body>
  42. </html>

There was a missing ".
Last edited by nav33n : Feb 6th, 2008 at 12:00 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 175
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help Re: login form and MySQL connection/validation error

  #9  
Feb 6th, 2008
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <title>Cycle Tracks Portal - Validation Page</title>
  6. <style type="text/css" media="all">@import "images/style.css";
  7. </style>
  8. <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. // connection to MySQL server
  14. mysql_connect('localhost','root','root');
  15. mysql_select_db('administration');
  16.  
  17. // *** Validate request to login to this site.
  18. //session_start();
  19.  
  20. if (isset($_POST['username'])) {
  21. $loginUsername=$_POST['username'];
  22. $password=$_POST['password'];
  23. $MM_redirectLoginSuccess = "validate.php";
  24. $MM_redirectLoginFailed = "index.html;
  25. $MM_redirecttoReferrer = true;
  26. mysql_select_db('administration');
  27.  
  28. $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'");
  29. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  30. $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  31. $loginFoundUser = mysql_num_rows($LoginRS);
  32. if ($loginFoundUser) {
  33.  
  34. header("Location: " . $MM_redirectLoginSuccess );
  35. }
  36. else {
  37. header("Location: ". $MM_redirectLoginFailed );
  38. }
  39. ?>
  40.  
  41. </body>
  42. </html>
  43.  

Sorry it was a paste mistake. The previous error was still there even though the code has been corrected. pls help.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: login form and MySQL connection/validation error

  #10  
Feb 6th, 2008
line 24. $MM_redirectLoginFailed = "index.html; <<< you haven't closed it.
It should have been
$MM_redirectLoginFailed = "index.html";
Use the code that I have posted in previous post. I guess it will work. Your new modified code has a different select query !
Last edited by nav33n : Feb 6th, 2008 at 12:02 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:41 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC