Help Please!!! Warning: mysql_num_rows():

Reply

Join Date: Apr 2006
Posts: 3
Reputation: MsKazza is an unknown quantity at this point 
Solved Threads: 0
MsKazza MsKazza is offline Offline
Newbie Poster

Help Please!!! Warning: mysql_num_rows():

 
0
  #1
Apr 27th, 2006
Hi there,
I keep getting the following error message when i run this script:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/tellproperties.com/httpdocs/testing/register.php on line 42

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/tellproperties.com/httpdocs/testing/register.php on line 43
No Database Selected

  1.  
  2. <?
  3. include 'listing.php';
  4. // Define post FIELDS INTO simple variables
  5. $first_name = $_POST['first_name'];
  6. $last_name = $_POST['last_name'];
  7. $email_address = $_POST['email_address'];
  8. $username = $_POST['username'];
  9. $info = $_POST['info'];
  10. /* Let's strip some slashes in case the user entered
  11. any escaped characters. */
  12. $first_name = stripslashes($first_name);
  13. $last_name = stripslashes($last_name);
  14. $email_address = stripslashes($email_address);
  15. $username = stripslashes($username);
  16. $info = stripslashes($info);
  17. /* Do some error checking on the form posted fields */
  18. if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
  19. echo 'You did not submit the following required information! <br />';
  20. if(!$first_name){
  21. echo "First Name is a required field. Please enter it below.<br />";
  22. }
  23. if(!$last_name){
  24. echo "Last Name is a required field. Please enter it below.<br />";
  25. }
  26. if(!$email_address){
  27. echo "Email Address is a required field. Please enter it below.<br />";
  28. }
  29. if(!$username){
  30. echo "Desired Username is a required field. Please enter it below.<br />";
  31. }
  32. include 'join_form.html'; // SHOW the form again!
  33. /* End the error checking and if everything is ok, we'll move on to
  34.   creating the user account */
  35. exit(); // if the error checking has failed, we'll exit the script!
  36. }
  37. /* Let's DO SOME checking AND ensure that the user's email address or username
  38. does not exist in the database */
  39. $sql_email_check = mysql_query("SELECT email_address FROM users
  40. WHERE email_address='$email_address'");
  41. $sql_username_check = mysql_query("SELECT username FROM users
  42. WHERE username='$username'");
  43. $email_check = mysql_num_rows($sql_email_check);
  44. $username_check = mysql_num_rows($sql_username_check);
  45. if(($email_check > 0) || ($username_check > 0)){
  46. echo "Please fix the following errors: <br />";
  47. if($email_check > 0){
  48. echo "<strong>Your email address has already been used by another member
  49. in our database. Please submit a different Email address!<br />";
  50. unset($email_address);
  51. }
  52. if($username_check > 0){
  53. echo "The username you have selected has already been used by another member
  54. in our database. Please choose a different Username!<br />";
  55. unset($username);
  56. }
  57. include 'join_form.html'; // Show the form again!
  58. exit(); // exit the script so that we do not create this account!
  59. }
  60. /* Everything has passed both error checks that we have done.
  61. It's TIME to CREATE the account! */
  62. /* Random Password generator.
  63. <a rel="nofollow" class="t" href="http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php" target="_blank">http://www.phpfreaks.com/quickcode/R...nerator/56.php</a>
  64. We'll generate a random password for the
  65. user and encrypt it, email it and then enter it into the db. */
  66. function makeRandomPassword() {
  67. $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  68. srand((DOUBLE)microtime()*1000000);
  69. $i = 0;
  70. while ($i <= 7) {
  71. $num = RAND() % 33;
  72. $tmp = substr($salt, $num, 1);
  73. $pass = $pass . $tmp;
  74. $i++;
  75. }
  76. return $pass;
  77. }
  78. $random_password = makeRandomPassword();
  79. $db_password = MD5($random_password);
  80. // Enter info INTO the Database.
  81. $info2 = htmlspecialchars($info);
  82. $sql = mysql_query("INSERT INTO users (first_name, last_name,
  83. email_address, username, password, info, signup_date)
  84. VALUES('$first_name', '$last_name', '$email_address',
  85. '$username', '$db_password', '$info2', now())")
  86. OR die (mysql_error());
  87. if(!$sql){
  88. echo 'There has been an error creating your account. Please contact the webmaster.';
  89. } ELSE {
  90. $userid = mysql_insert_id();
  91. // Let's mail the user!
  92. $subject = "Your Membership at MyWebsite!";
  93. $message = "Dear $first_name $last_name,
  94. Thank you for registering at our website, <a rel="nofollow" class="t" href="http://www.mydomain.com/" target="_blank">http://www.mydomain.com</a>!
  95. You are two steps away from logging in and accessing our exclusive members area.
  96. To activate your membership,
  97. please click here: <a rel="nofollow" class="t" href="http://www.mydomain.com/activate.php?id=$userid&code=$db_password" target="_blank">http://www.mydomain.com/activate.php...e=$db_password</a>
  98. Once you activate your memebership, you will be able to login
  99. with the following information:
  100. Username: $username
  101. Password: $random_password
  102. Thanks!
  103. The Webmaster
  104. This is an automated response, please do not reply!";
  105. mail($email_address, $subject, $message,
  106. "From: MyDomain Webmaster<admin@mydomain.com>\n
  107. X-Mailer: PHP/" . phpversion());
  108. echo 'Your membership information has been mailed to your email address!
  109. Please CHECK it AND follow the directions!';
  110. }
  111. ?>
  112.  

and this is my listing.php file:

  1.  
  2. <?php
  3. # FileName="Connection_php_mysql.htm"
  4. # Type="MYSQL"
  5. # HTTP="true"
  6. $hostname_listing = "localhost";
  7. $database_listing = "listing";
  8. $username_listing = "admin";
  9. $password_listing = "helpme";
  10. $listing = mysql_pconnect($hostname_listing, $username_listing, $password_listing) OR trigger_error(mysql_error(),E_USER_ERROR);
  11. ?>

when i comment out line 42 and 43 i just get left with No database selected.

If anyone can tell me what is wrong i would really appreciate it, i´m trying to learn how to make a membership system in dreamweaver using php and mysql.

thanks in advance for your help.

MsKazza
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: karenhoe is an unknown quantity at this point 
Solved Threads: 0
karenhoe karenhoe is offline Offline
Newbie Poster

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #2
Apr 28th, 2006
$sql_email_check = mysql_query("SELECT email_address FROM users
WHERE email_address=\"$email_address\"");
$sql_username_check = mysql_query("SELECT username FROM users
WHERE username=\"$username\"");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

try this... hope can get it...



Originally Posted by MsKazza
Hi there,
I keep getting the following error message when i run this script:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/tellproperties.com/httpdocs/testing/register.php on line 42

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/tellproperties.com/httpdocs/testing/register.php on line 43
No Database Selected

  1.  
  2. <?
  3. include 'listing.php';
  4. // Define post FIELDS INTO simple variables
  5. $first_name = $_POST['first_name'];
  6. $last_name = $_POST['last_name'];
  7. $email_address = $_POST['email_address'];
  8. $username = $_POST['username'];
  9. $info = $_POST['info'];
  10. /* Let's strip some slashes in case the user entered
  11. any escaped characters. */
  12. $first_name = stripslashes($first_name);
  13. $last_name = stripslashes($last_name);
  14. $email_address = stripslashes($email_address);
  15. $username = stripslashes($username);
  16. $info = stripslashes($info);
  17. /* Do some error checking on the form posted fields */
  18. if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
  19. echo 'You did not submit the following required information! <br />';
  20. if(!$first_name){
  21. echo "First Name is a required field. Please enter it below.<br />";
  22. }
  23. if(!$last_name){
  24. echo "Last Name is a required field. Please enter it below.<br />";
  25. }
  26. if(!$email_address){
  27. echo "Email Address is a required field. Please enter it below.<br />";
  28. }
  29. if(!$username){
  30. echo "Desired Username is a required field. Please enter it below.<br />";
  31. }
  32. include 'join_form.html'; // SHOW the form again!
  33. /* End the error checking and if everything is ok, we'll move on to
  34.   creating the user account */
  35. exit(); // if the error checking has failed, we'll exit the script!
  36. }
  37. /* Let's DO SOME checking AND ensure that the user's email address or username
  38. does not exist in the database */
  39. $sql_email_check = mysql_query("SELECT email_address FROM users
  40. WHERE email_address='$email_address'");
  41. $sql_username_check = mysql_query("SELECT username FROM users
  42. WHERE username='$username'");
  43. $email_check = mysql_num_rows($sql_email_check);
  44. $username_check = mysql_num_rows($sql_username_check);
  45. if(($email_check > 0) || ($username_check > 0)){
  46. echo "Please fix the following errors: <br />";
  47. if($email_check > 0){
  48. echo "<strong>Your email address has already been used by another member
  49. in our database. Please submit a different Email address!<br />";
  50. unset($email_address);
  51. }
  52. if($username_check > 0){
  53. echo "The username you have selected has already been used by another member
  54. in our database. Please choose a different Username!<br />";
  55. unset($username);
  56. }
  57. include 'join_form.html'; // Show the form again!
  58. exit(); // exit the script so that we do not create this account!
  59. }
  60. /* Everything has passed both error checks that we have done.
  61. It's TIME to CREATE the account! */
  62. /* Random Password generator.
  63. <a rel="nofollow" class="t" href="http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php" target="_blank">http://www.phpfreaks.com/quickcode/R...nerator/56.php</a>
  64. We'll generate a random password for the
  65. user and encrypt it, email it and then enter it into the db. */
  66. function makeRandomPassword() {
  67. $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  68. srand((DOUBLE)microtime()*1000000);
  69. $i = 0;
  70. while ($i <= 7) {
  71. $num = RAND() % 33;
  72. $tmp = substr($salt, $num, 1);
  73. $pass = $pass . $tmp;
  74. $i++;
  75. }
  76. return $pass;
  77. }
  78. $random_password = makeRandomPassword();
  79. $db_password = MD5($random_password);
  80. // Enter info INTO the Database.
  81. $info2 = htmlspecialchars($info);
  82. $sql = mysql_query("INSERT INTO users (first_name, last_name,
  83. email_address, username, password, info, signup_date)
  84. VALUES('$first_name', '$last_name', '$email_address',
  85. '$username', '$db_password', '$info2', now())")
  86. OR die (mysql_error());
  87. if(!$sql){
  88. echo 'There has been an error creating your account. Please contact the webmaster.';
  89. } ELSE {
  90. $userid = mysql_insert_id();
  91. // Let's mail the user!
  92. $subject = "Your Membership at MyWebsite!";
  93. $message = "Dear $first_name $last_name,
  94. Thank you for registering at our website, <a rel="nofollow" class="t" href="http://www.mydomain.com/" target="_blank">http://www.mydomain.com</a>!
  95. You are two steps away from logging in and accessing our exclusive members area.
  96. To activate your membership,
  97. please click here: <a rel="nofollow" class="t" href="http://www.mydomain.com/activate.php?id=$userid&code=$db_password" target="_blank">http://www.mydomain.com/activate.php...e=$db_password</a>
  98. Once you activate your memebership, you will be able to login
  99. with the following information:
  100. Username: $username
  101. Password: $random_password
  102. Thanks!
  103. The Webmaster
  104. This is an automated response, please do not reply!";
  105. mail($email_address, $subject, $message,
  106. "From: MyDomain Webmaster<admin@mydomain.com>\n
  107. X-Mailer: PHP/" . phpversion());
  108. echo 'Your membership information has been mailed to your email address!
  109. Please CHECK it AND follow the directions!';
  110. }
  111. ?>
  112.  

and this is my listing.php file:

  1.  
  2. <?php
  3. # FileName="Connection_php_mysql.htm"
  4. # Type="MYSQL"
  5. # HTTP="true"
  6. $hostname_listing = "localhost";
  7. $database_listing = "listing";
  8. $username_listing = "admin";
  9. $password_listing = "helpme";
  10. $listing = mysql_pconnect($hostname_listing, $username_listing, $password_listing) OR trigger_error(mysql_error(),E_USER_ERROR);
  11. ?>

when i comment out line 42 and 43 i just get left with No database selected.

If anyone can tell me what is wrong i would really appreciate it, i´m trying to learn how to make a membership system in dreamweaver using php and mysql.

thanks in advance for your help.

MsKazza
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 3
Reputation: MsKazza is an unknown quantity at this point 
Solved Threads: 0
MsKazza MsKazza is offline Offline
Newbie Poster

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #3
Apr 28th, 2006
Thanks for that, but it didn´t make any difference.
I know that the listing.php connection file works cause the rest of my site is using it, but i still think that it might be somehow related to that file.
Even if i delete that whole section for the email and username check i still get the error No Database Selected.

This has been driving me nuts for days, any more suggestions much appreciated.

Thanks

MsKazza



Originally Posted by karenhoe
$sql_email_check = mysql_query("SELECT email_address FROM users
WHERE email_address=\"$email_address\"");
$sql_username_check = mysql_query("SELECT username FROM users
WHERE username=\"$username\"");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

try this... hope can get it...
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: karenhoe is an unknown quantity at this point 
Solved Threads: 0
karenhoe karenhoe is offline Offline
Newbie Poster

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #4
Apr 28th, 2006
$listing = mysql_connect($hostname_listing, $username_listing, $password_listing) or trigger_error(mysql_error(),E_USER_ERROR);
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: karenhoe is an unknown quantity at this point 
Solved Threads: 0
karenhoe karenhoe is offline Offline
Newbie Poster

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #5
Apr 28th, 2006
In the php didn't have a command mysql_pconnect
should be mysql_connect
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 3
Reputation: MsKazza is an unknown quantity at this point 
Solved Threads: 0
MsKazza MsKazza is offline Offline
Newbie Poster

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #6
Apr 28th, 2006
Error still there but now says 43 and 44 still no database selected error too.
Your help is much appreciated though, thanks
MsKazza
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 50
Reputation: barnamos is an unknown quantity at this point 
Solved Threads: 0
barnamos's Avatar
barnamos barnamos is offline Offline
Junior Poster in Training

Re: Help Please!!! Warning: mysql_num_rows():

 
0
  #7
May 8th, 2006
No to be silly but "No database selected" means "no database selected".

You need a mysql_select_db($database_name,$listing);

:-)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC