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 456,552 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,472 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: 665 | Replies: 9
Reply
Join Date: Oct 2007
Posts: 3
Reputation: djwakko18 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
djwakko18 djwakko18 is offline Offline
Newbie Poster

I need Support please (PHP Code)

  #1  
Oct 17th, 2007
I have this code and when i try run it i got a menssage"PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\bla bla bla.......... on line 15

i will thankfull if anybody can help me
------------


  1. <?php
  2. session_start();
  3.  
  4. if ($userid && $password)
  5. {
  6. // si el usuario ha intentado hacer log in
  7.  
  8. $db_conn=mysql_connect("localhost","root","mysql");
  9. mysql_select_db('proyecto',$db_conn);
  10. $query="select * from auth"
  11. ."where name='$userid'"
  12. ."and pass=password('$password')";
  13. $result=mysql_query($query,$db_conn);
  14. if (mysql_num_rows($result)>0) // <----- THIS IS THE LINE 15
  15. {
  16. // si estan en la base de datos registra la id de usuario
  17. $valid_user=$userid;
  18. session_register("valid_user");
  19. }
  20. }
  21. ?>
  22. <html>
  23. <body>
  24. <h1>Página Inicio</h1>
  25.  
  26. <?php
  27. if (session_is_registered("valid_user"))
  28. {
  29. echo "Ahora estas logged in como: $valid_user <br>";
  30. echo "<a href=\"logout.php\">Log out</a><br>";
  31. }
  32. else
  33. {
  34. if(isset($userid))
  35. {
  36. // si han intentado hacer login y ha fallado
  37. echo "No has podido hacer login";
  38. }
  39. else
  40. {
  41. // si no han intentado hacer login o han hecho logged out
  42. echo "Ahora estas logged out.<br>";
  43. }
  44.  
  45. // provee el formulario para hacer log in
  46. echo "<form method=post action=\"authmain.php\">";
  47. echo "<table>";
  48. echo "<tr><td>Userid:</td>";
  49. echo "<td><input type=text name=userid> </td></tr>";
  50. echo "<tr><td>Contraseña:</td>";
  51. echo "<td><input type=password name=password> </td></tr>";
  52. echo "<tr><td colspan=2 aling=center>";
  53. echo "<input type=submit value=\"Log in\"> <td></tr>";
  54. echo "</table></form>";
  55. }
  56. ?>
  57. <br>
  58. <a href="members_only.php">Sección de Miembros</a>
  59. </body>
  60. </html>
Last edited by stymiee : Oct 17th, 2007 at 2:54 pm. Reason: Please use code tags when posting code
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: I need Support please (PHP Code)

  #2  
Oct 17th, 2007
if (mysql_num_rows($result)>0)

change it to this:

if (mysql_num_rows($result) != 0)

if you need to check, when there is no record

if (mysql_num_rows($result) != 0)
{
/* your code goes here */
}
else
{
print "there is no record";
}
Last edited by fatihpiristine : Oct 17th, 2007 at 4:01 pm.
Do a favour, leave me alone
Reply With Quote  
Join Date: Feb 2007
Location: india
Posts: 52
Reputation: ajay_tabbu is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ajay_tabbu's Avatar
ajay_tabbu ajay_tabbu is offline Offline
Junior Poster in Training

Re: I need Support please (PHP Code)

  #3  
Oct 17th, 2007
I don't know y u r gating warning but as I see u code there is no problem.u just try to use an alternativ way for this try to use
$query="select count(*) from auth"
."where name='$userid'"
."and pass=password('$password')";

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("UserID: %s Password: %s", $row[0], $row[1]);
}


for the same purpus i right some code which was as follow

if($row = mysql_fetch_array($result))
            {
                
                header('Location: wellcome.php');
            }
            else
            {    
                $message='Invalid User or Password';                
            }
Last edited by ajay_tabbu : Oct 17th, 2007 at 4:13 pm.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: djwakko18 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
djwakko18 djwakko18 is offline Offline
Newbie Poster

Re: I need Support please (PHP Code)

  #4  
Oct 17th, 2007
thanks, but it doesn´t work
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: I need Support please (PHP Code)

  #5  
Oct 17th, 2007
what is thet there??

."and pass=password('$password')";

guess it should be:
."and pass='$password'";



your code work with me in this way

$query="select * from auth where name='" . $userid . "' and pass='" . $password . "')";
Do a favour, leave me alone
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: djwakko18 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
djwakko18 djwakko18 is offline Offline
Newbie Poster

Re: I need Support please (PHP Code)

  #6  
Oct 18th, 2007
i continous with the same problem, maybe, the problem is in another place.
Reply With Quote  
Join Date: Oct 2007
Posts: 38
Reputation: kevindougans is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
kevindougans kevindougans is offline Offline
Light Poster

Re: I need Support please (PHP Code)

  #7  
Oct 18th, 2007
Hello,

Change the following:

$result=mysql_query($query,$db_conn);

to

$result=mysql_query($query,$db_conn) or die(mysql_error());

Now you should see where the problem is :-)

Regards,

Kevin Dougans
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: I need Support please (PHP Code)

  #8  
Oct 18th, 2007
Originally Posted by kevindougans View Post
Hello,

Change the following:

$result=mysql_query($query,$db_conn);

to

$result=mysql_query($query,$db_conn) or die(mysql_error());

Now you should see where the problem is :-)

Regards,

Kevin Dougans



it has no sense
Do a favour, leave me alone
Reply With Quote  
Join Date: Oct 2007
Posts: 38
Reputation: kevindougans is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
kevindougans kevindougans is offline Offline
Light Poster

Re: I need Support please (PHP Code)

  #9  
Oct 18th, 2007
Originally Posted by fatihpiristine View Post
it has no sense


Yes it does... because the PHP has just told him that $result is not a valid php/mysql response.

My fix will tell him where the problem is, which almost certainly is in his SQL statement. For example the password field may actually be called "pword" instead of "password" and thats why it can't return a valid result.
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: I need Support please (PHP Code)

  #10  
Oct 18th, 2007
You have a problem in the way your query string is written (because of the way you wrote it, you missed some spaces, between auth and where and between '$userid' and and:
$query="select * from auth" 
."where name='$userid'"
."and pass=password('$password')";
this query is, in fact, this:
$query="select * from authwhere name='$userid'and pass=password('$password')";
which, obviously, is wrong;
And the part with the password is probably wrong: it should probably be pass='$password'

So, try this query in your script:
$query="select * from auth where name='$userid' and pass='$password'";
Since you don't escape the userid and password variables, you are also in trouble if any of them contains a ' or " or # and maybe other special characters.

Also, from the way your script looks, it seems to me that you are using register_globals = on. This is very bad. Set it to off and get your post variables like this:
 $userid = $_POST['userid'];
$password = $_POST['password'];
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 5:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC