| | |
Help Please!!! Warning: mysql_num_rows():
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
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
and this is my listing.php file:
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
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
MySQL Syntax (Toggle Plain Text)
<? include 'listing.php'; // Define post FIELDS INTO simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // SHOW the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's DO SOME checking AND ensure that the user's email address or username does not exist in the database */ $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); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's TIME to CREATE the account! */ /* Random Password generator. <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> We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((DOUBLE)microtime()*1000000); $i = 0; while ($i <= 7) { $num = RAND() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = MD5($random_password); // Enter info INTO the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") OR die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } ELSE { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at MyWebsite!"; $message = "Dear $first_name $last_name, Thank you for registering at our website, <a rel="nofollow" class="t" href="http://www.mydomain.com/" target="_blank">http://www.mydomain.com</a>! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, 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> Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please CHECK it AND follow the directions!'; } ?>
and this is my listing.php file:
MySQL Syntax (Toggle Plain Text)
<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_listing = "localhost"; $database_listing = "listing"; $username_listing = "admin"; $password_listing = "helpme"; $listing = mysql_pconnect($hostname_listing, $username_listing, $password_listing) OR trigger_error(mysql_error(),E_USER_ERROR); ?>
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
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
$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...
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
MySQL Syntax (Toggle Plain Text)
<? include 'listing.php'; // Define post FIELDS INTO simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // SHOW the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's DO SOME checking AND ensure that the user's email address or username does not exist in the database */ $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); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's TIME to CREATE the account! */ /* Random Password generator. <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> We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((DOUBLE)microtime()*1000000); $i = 0; while ($i <= 7) { $num = RAND() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = MD5($random_password); // Enter info INTO the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") OR die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } ELSE { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at MyWebsite!"; $message = "Dear $first_name $last_name, Thank you for registering at our website, <a rel="nofollow" class="t" href="http://www.mydomain.com/" target="_blank">http://www.mydomain.com</a>! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, 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> Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\n X-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please CHECK it AND follow the directions!'; } ?>
and this is my listing.php file:
MySQL Syntax (Toggle Plain Text)
<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_listing = "localhost"; $database_listing = "listing"; $username_listing = "admin"; $password_listing = "helpme"; $listing = mysql_pconnect($hostname_listing, $username_listing, $password_listing) OR trigger_error(mysql_error(),E_USER_ERROR); ?>
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
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
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
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...
![]() |
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
- Warning: mysql_num_rows(): (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the MySQL Forum
- Previous Thread: php & mysql
- Next Thread: Multiple databases/separate sites in mysql
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency





