943,151 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 371
  • PHP RSS
Mar 19th, 2010
0

hi i am new to php i am getting the following error. i not getting wer the error.

Expand Post »
PHP Syntax (Toggle Plain Text)
  1. ----Query was empty---
  2. at
  3. ---$sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
  4. $result=@mysql_query($sql) or die(mysql_error()); ---
  5.  
  6.  
  7. <html>
  8. <body>
  9. <form action="login.php" method="post">
  10. <div>
  11. <table width="100%">
  12. <tr>
  13. <td><img src="Logofinalcopy.gif"></td>
  14. </tr>
  15. <tr>
  16. <td bgcolor="aqua"><h2>Login</h2></td>
  17. </tr></table>
  18. <table align="right" style="width:40%">
  19. <br>
  20. <tr>
  21. <td>username:</td>
  22. <td><input type="text" name="username"></td>
  23. </tr>
  24. <tr>
  25. <td>password:</td>
  26. <td><input type="password" name="password"></td>
  27. </tr>
  28. <tr>
  29. <td align="CENTER" COLSPAN="4">
  30. <input TYPE="SUBMIT" name="submit" value="Login">
  31. <input TYPE="reset" name="submit" value="clear"></td>
  32. </tr>
  33. </table>
  34. </div>
  35. </form>
  36. </body>
  37. </html>
  38. <?php
  39. if(isset($_POST['submit']))
  40. {
  41. $con = @mysql_connect("10.70.1.50","invensis","invensis");
  42. if (!$con)
  43. {
  44. die('Could not connect: ' . mysql_error());
  45. }
  46. $con_db=@mysql_select_db("database_myproject",$con);
  47. if (!$con)
  48. {
  49. die('Could not connect DB: ' . mysql_error());
  50. }
  51.  
  52. $username=$_POST['username'];
  53. $password=$_POST['password'];
  54.  
  55. $username = stripslashes($username);
  56. $password = stripslashes($password);
  57. $username = mysql_real_escape_string($username);
  58. $password = mysql_real_escape_string($password);
  59.  
  60. $flag="OK";
  61. $msg="";
  62.  
  63. if(strlen($username) < 1)
  64. {
  65. $msg=$msg."Please enter the username<br>";
  66. $flag="NOTOK";
  67. }
  68. if(strlen($password) < 1)
  69. {
  70. $msg=$msg."Please enter the password<br>";
  71. $flag="NOTOK";
  72. }
  73. if($flag <>"OK")
  74. {
  75. echo "<strong style='color:#FF3333'>"."<left >Please enter Username or Password </left>"."</strong>";
  76. }
  77. else
  78. {
  79. $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
  80. $result=@mysql_query($sql) or die(mysql_error());
  81.  
  82. $count= mysql_num_rows($result);
  83. echo "$count";
  84. if($count==1)
  85. {
  86. $sql = mysql_query("SELECT role FROM users WHERE username='$username' AND password='$password'");
  87. while($info = @mysql_fetch_array($sql))
  88. {
  89. if($info['role']=='Super Admin')
  90. {
  91. @header('location: <a rel="nofollow" href="http://localhost/Project/Superadmin.php');" target="_blank">http://localhost/Project/Superadmin.php');</a>
  92. }
  93. else if($info['role']=='Admin')
  94. {
  95. @header('location: <a rel="nofollow" href="http://localhost/Project/Admin.php');" target="_blank">http://localhost/Project/Admin.php');</a>
  96. }
  97. else if($info['role']=='User')
  98. {
  99. @header("location: http://localhost/Project/User.php");
  100. }
  101. }
  102.  
  103. }
  104. else
  105. {
  106. echo "<strong style='color:#FF3333'>Incorrect User Name OR Password</strong>";
  107. }
  108.  
  109. }
  110. }
  111. ?>
Last edited by nav33n; Mar 19th, 2010 at 2:58 am. Reason: Use [code][/code] tags to wrap your code for easy readability.
Reputation Points: 9
Solved Threads: 2
Posting Whiz in Training
niths is offline Offline
299 posts
since Mar 2010
Mar 19th, 2010
0
Re: hi i am new to php i am getting the following error. i not getting wer the error.
hi

Your query will come like

"$sql="SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";

Please try with this one and let me know if still any problem comes
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
phpuser is offline Offline
55 posts
since May 2008
Mar 19th, 2010
0
Re: hi i am new to php i am getting the following error. i not getting wer the error.
Hiiee

Use This Query
PHP Syntax (Toggle Plain Text)
  1. $sql="SELECT * FROM users WHERE username="'.$username.'" AND password="'.$password.'" ";
InStead Of This
PHP Syntax (Toggle Plain Text)
  1. $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";

Check & Let Me Know If U Find Anything Else.

Do It For All Queries In Ur File. That Will Work.

Thanks.
ScmSimplyBest
Last edited by scmsimplybest; Mar 19th, 2010 at 3:24 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scmsimplybest is offline Offline
8 posts
since Aug 2009
Mar 19th, 2010
0
Re: hi i am new to php i am getting the following error. i not getting wer the error.
Do one thing ,

echo you $sql variable in your script then write die(); so when you run code you will see that query only.

Now take that query and run it in PHPMYADMIN and check is it right or your get result from same ??

may be you can get some idea wheres the problem is ?

Best luck..
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
phpuser is offline Offline
55 posts
since May 2008

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: include issues
Next Thread in PHP Forum Timeline: Get time and date like google??





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


Follow us on Twitter


© 2011 DaniWeb® LLC