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 401,956 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,099 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: 4944 | Replies: 2
Reply
Join Date: Jan 2007
Posts: 2
Reputation: mickeymoose is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mickeymoose mickeymoose is offline Offline
Newbie Poster

Help mysql_numrows(): supplied argument is not a valid MySQL result resource

  #1  
Jan 11th, 2007
Hi, I'm quite new to PHP and MYSQL, but I have chosen to do an A-level project in it. This is just a basic registering page, which I've copied and modified from one out of a book. That one works, but this doesn't, saying that "mysql_numrows(): supplied argument is not a valid MySQL result resource". I hope that makes sense to someone.

  1. <?php #Script 8.7 - register.php
  2. //SEND NOTHING TO BROWSER BEFORE HEADER()
  3.  
  4. //Check if form is sumbitted
  5. if (isset($_POST['submitted'])) {
  6.  
  7. require_once('../mysql_pp_connect.php');
  8.  
  9. $errors = array();
  10.  
  11. //Validate crap
  12. if (empty($_POST['title'])) {
  13. $errors[] = 'You forgot to enter your first name.';
  14. } else {
  15. $t = escape_data($_POST['title']);
  16. }
  17.  
  18. if (empty($_POST['first_name'])) {
  19. $errors[] = 'You forgot to enter your first name.';
  20. } else {
  21. $fn = escape_data($_POST['first_name']);
  22. }
  23.  
  24. if (empty($_POST['last_name'])) {
  25. $errors[] = 'You forgot to enter your last name.';
  26. } else {
  27. $ln = escape_data($_POST['last_name']);
  28. }
  29.  
  30. if (empty($_POST['addressline1'])) {
  31. $errors[] = 'You forgot to enter your address.';
  32. } else {
  33. $al1 = escape_data($_POST['addressline1']);
  34. }
  35.  
  36. $al2 = escape_data($_POST['addressline2']);
  37. $al3 = escape_data($_POST['addressline3']);
  38.  
  39. if (empty($_POST['postcode'])) {
  40. $errors[] = 'You forgot to enter your postcode.';
  41. } else {
  42. $pc = escape_data($_POST['postcode']);
  43. }
  44.  
  45. if (empty($_POST['email'])) {
  46. $errors[] = 'You forgot to enter your email address.';
  47. } else {
  48. $e = escape_data($_POST['email']);
  49. }
  50.  
  51. if (empty($_POST['phone_number'])) {
  52. $errors[] = 'You forgot to enter your phone number.';
  53. } else {
  54. $pn = escape_data($_POST['phone_number']);
  55. }
  56.  
  57. if(!empty($_POST['password1'])) {
  58. if($_POST['password1'] != $_POST['password2']) {
  59. $errors[] = "Your passwords didn't match";
  60. } else {
  61. $p = escape_data($_POST['password1']);
  62. }
  63. } else {
  64. $errors[] = "You didn't enter a password!";
  65. }
  66.  
  67. if (empty($errors)) {
  68.  
  69. $query = "SELECT user_id FROM users WHERE email='$e'";
  70. $result = mysql_query ($query);
  71. if (mysql_num_rows($result) == 0) {
  72.  
  73. //Make query
  74. $query = "INSERT INTO customers (Title, FirstName, LastName, AddressLine1, AddressLine2, Addressline3, Postcode, EmailAddress, PhoneNumber, Password) VALUES ('$t', '$fn', '$ln', '$al1', '$al2', '$al3', '$pc', '$e', '$pn', SHA('$p'))";
  75. $result = @mysql_query ($query); //Run query
  76.  
  77. if ($result) {
  78.  
  79. //send email blah blah
  80.  
  81. //redirect to thanks.php page
  82. //start defining url
  83. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
  84.  
  85. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\')) {
  86. $url = substr($url, 0, -1); //chop off slashah.
  87. }
  88.  
  89. $url .= '/thanks.php';
  90.  
  91. header("Location: $url");
  92. exit();
  93.  
  94. } else {
  95. $errors[] = 'You could not be registered due to a system error. oops. sorry!';
  96. $errors[] = mysql_error() . '<p>Query ' . $query;
  97. }
  98.  
  99. } else {
  100. $errors = 'The email address has already been registered!';
  101. }
  102.  
  103. }
  104. mysql_close();
  105.  
  106. }else{
  107. $errors = NULL;
  108. } //end of submit conditional
  109. $page_title = 'Register';
  110. include ('./header.html');
  111.  
  112. if(!empty($errors)){
  113. echo '<h1 id="mainhead">Error!</h1><p class="error">The following errors occurred:<br><ul>';
  114. foreach ($errors as $msg) {
  115. echo "<li>$msg</li><br>";
  116. }
  117. echo '</ul><p>Please try again';
  118. } //end of if empty errrors if
  119. ?>

Cheers
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: mysql_numrows(): supplied argument is not a valid MySQL result resource

  #2  
Jan 11th, 2007
Your query probably fails, try debugging:
[php]
$result = mysql_query ($query) or die(mysql_error());
[/php]
Reply With Quote  
Join Date: Jan 2007
Posts: 2
Reputation: mickeymoose is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mickeymoose mickeymoose is offline Offline
Newbie Poster

Re: mysql_numrows(): supplied argument is not a valid MySQL result resource

  #3  
Jan 11th, 2007
Yay, thanks. That was it, I'd forgotten my table was called something different. Thanks again.
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:53 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC