943,752 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 641
  • PHP RSS
Feb 2nd, 2009
0

supplied argument is not a valid

Expand Post »
i don't know if this is enough you to help me but looking at this could you tell me what i could do to fix it?
PHP Syntax (Toggle Plain Text)
  1. $user_check = mysql_query("SELECT userdb_user_name FROM default_userdb WHERE userdb_user_name='$reciever'");
  2. $user_check = mysql_num_rows($user_check);
  3.  
  4. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /xx/xx/x/xx/xx/xx/xxxx/xxxxx/htdocs/xxxx/xxx/xxx.php
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

Click to Expand / Collapse  Quote originally posted by serdas ...
i don't know if this is enough you to help me but looking at this could you tell me what i could do to fix it?
PHP Syntax (Toggle Plain Text)
  1. $user_check = mysql_query("SELECT userdb_user_name FROM default_userdb WHERE userdb_user_name='$reciever'");
  2. $user_check = mysql_num_rows($user_check);
  3.  
  4. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /xx/xx/x/xx/xx/xx/xxxx/xxxxx/htdocs/xxxx/xxx/xxx.php
Your query did not execute.

at least add this check after the $user_check line:
PHP Syntax (Toggle Plain Text)
  1. if (!$user_check) {
  2. die('Invalid query: ' . mysql_error());
  3. }

You may want to try to pass a valid mysql connection link as a second argument to mysql_query function

This should be the result of your mysql_connect() function.
Reputation Points: 18
Solved Threads: 7
Light Poster
uncle_smith is offline Offline
49 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

how ould i do this

You may want to try to pass a valid mysql connection link as a second argument to mysql_query function
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

Click to Expand / Collapse  Quote originally posted by serdas ...
how ould i do this

You may want to try to pass a valid mysql connection link as a second argument to mysql_query function
Carefully

Just kidding.

Well, how do you connect to mysql database? Do you have the mysql_connect() function anywhere in your code?
Reputation Points: 18
Solved Threads: 7
Light Poster
uncle_smith is offline Offline
49 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

lol

yes i do but not in the same one but connection work. because before this it checks that if the user loged in. this is suppose to check when the loged in user is trying to send a pm to an other user if user name exist in the datebase but keep getting error, it is not finding the user even thogh that user exist.
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

Ok, then after the first
$user_check

add this line and see what mysql complains about:

php Syntax (Toggle Plain Text)
  1. if (!$user_check) {
  2. die('Invalid query: ' . mysql_error());
  3. }
Last edited by peter_budo; Feb 3rd, 2009 at 1:38 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 18
Solved Threads: 7
Light Poster
uncle_smith is offline Offline
49 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

my main error is this
'That username does not exist, please try again. Remember to check your spelling, and don\'t make stuff up at random.';

and then the warning i gave in the previuos post.

i don't know where i should put that. i think i have something like that and it passes. but just don't find the user to send when there.
here is the code, maybe this make more sense.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. $user = $_SESSION['username'];
  4. $reciever = $_REQUEST['reciever'];
  5.  
  6. include 'db.php';
  7.  
  8. //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists.
  9. //You could change this check to however you want to validate your members, this is just how I did it.
  10. if(!$user)
  11. {
  12. echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
  13. }
  14.  
  15. else
  16. {
  17. //Query the database to see how many messages the logged in user has, then do a little math
  18. //Find the percentage that your inbox is full (message count divided by 50)
  19. //50 messages maximum, you can change that
  20. $sql = mysql_query ("SELECT pm_count FROM default_userdb WHERE userdb_user_name='$user'");
  21. $row = mysql_fetch_array ($sql);
  22. $pm_count = $row['pm_count'];
  23.  
  24. //This is the math to figure out the percentage.
  25. //The message could divided by 50 then multiplied by 100 so we dont have a number less than 1
  26. $percent = $pm_count/'50';
  27. $percent = $percent * '100';
  28. ?>
  29. <br>
  30. <center>
  31. <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
  32. <b><p><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b>
  33. </center>
  34. <br>
  35. <?php
  36. //So here we get the variable submitted through the form to this page
  37. if($reciever == NULL)
  38. {
  39. $reciever = $_POST['username'];
  40. }
  41. $subject = $_POST['subject'];
  42. $message = $_POST['message'];
  43. $error = '0';
  44.  
  45. //If they are all blank we jsut say to compose a message
  46. if(!$reciever AND !$subject AND !$message)
  47. {
  48. ?>
  49. <p><b>Please compose a message.</b></p>
  50. <br>
  51. <?php
  52. }
  53.  
  54. //Since this form was partially filled out we need to return an error message
  55. else
  56. {
  57. if (!$reciever)
  58. {
  59. $error = 'You must enter a reciever to your message';
  60. }
  61.  
  62. if (!$subject)
  63. {
  64. $error = 'You must enter a subject';
  65. }
  66.  
  67. if (!$message)
  68. {
  69. $error = 'You must enter a message';
  70. }
  71.  
  72. //If the variable error is not set to zero, we have a problem and should show the error message
  73. if($error != '0')
  74. {
  75. echo "<p>$error</p><br>";
  76. }
  77.  
  78. //There are no errors so far which means the form is completely filled out
  79. else
  80. {
  81. //Are the trying to send a message to a real user or to something they just made up?
  82. $user_check = mysql_query("SELECT userdb_user_name FROM default_userdb WHERE userdb_user_name='$reciever'");
  83. $user_check = mysql_num_rows($user_check);
  84.  
  85. //The user is real and not made up if this is true
  86. if($user_check > '0')
  87. {
  88. //There might already be a sessioned time variable, if so we need to get it for the flood check
  89. $time = $_SESSION['time'];
  90.  
  91. //If there is a time variable already, set it to the varialbe $old_time
  92. if($time > '0')
  93. {
  94. $old_time = $time;
  95. }
  96.  
  97. //Here we get the minutes and seconds on the server time using the date function, and set that to the $time variable
  98. //Now we find the difference between this time ($time) and the time that the page was submitted ($old_time)
  99. $time = date('is');
  100. $difference = $time - $old_time;
  101.  
  102. $_SESSION['time'] = $time;
  103.  
  104. //If the two times have a difference greater or equal to 15, which is 15 seconds, they can submit the message, this is for flood protection
  105. if($difference >= '15')
  106. {
  107. //Get their private message count
  108. $sql = mysql_query ("SELECT pm_count FROM default_userdb WHERE username='$reciever'");
  109. $row = mysql_fetch_array ($sql);
  110. $pm_count = $row['pm_count'];
  111.  
  112. //You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
  113. if(pm_count == '50')
  114. {
  115. $error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
  116. }
  117.  
  118. else
  119. {
  120. //And now we stick the message in the database with all the correct information
  121. mysql_query("INSERT INTO messages (reciever, sender, subject, message) VALUES('$reciever', '$user', '$subject', '$message')") or die (mysql_error());
  122. //Add 1 to the pm count, update the reciever with the new pm count
  123. $pm_count++;
  124. mysql_query("UPDATE default_userdb SET pm_count='$pm_count' WHERE username='$reciever'");
  125. }
  126.  
  127. //Let the user know everything went ok.
  128. echo "<p><b>You have successfully sent a private message!</b></p><br>";
  129. }
  130.  
  131. //Since they are trying to send messages faster than every 15 seconds, give them an error message
  132. else
  133. {
  134. $error = 'You must wait 15 seconds before sending another private message';
  135. }
  136. }
  137.  
  138. //If they mis spelled or, made up a username, then give an error message telling them its wrong.
  139. else
  140. {
  141. $error = 'That username does not exist, please try again. Remember to check your spelling, and don\'t make stuff up at random.';
  142. }
  143. }
  144. }
  145.  
  146. //Since we may have set the error variable to something while trying to send the messae, we need another error check
  147. if($error != '0')
  148. {
  149. echo "<p>$error</p><br>";
  150. }
  151.  
  152. //else
  153. // {
  154. //Here's the form for the input
  155. ?>
  156. <form name="send" method="post" action="compose.php">
  157. <table width="80%">
  158. <tr>
  159. <td width="150px" align="left" valign="top"><p>Username</p></td>
  160. <td width="" align="left" valign="top"><input name="username" type="text" id="username" value="<?php echo "$reciever"; ?>"></td>
  161. </tr>
  162.  
  163. <tr>
  164. <td width="150px" align="left" valign="top"><p>Subject</p></td>
  165. <td width="" align="left" valign="top"><input name="subject" type="text" id="subject" value="<?php echo "$subject"; ?>"></td>
  166. </tr>
  167.  
  168. <tr>
  169. <td width="150px" align="left" valign="top"><p>Message Body</p></td>
  170. <td width="" align="left" valign="top"><textarea name="message" type="text" id="message" value="" cols="50" rows="10"></textarea></td>
  171. </tr>
  172.  
  173. <tr>
  174. <td></td>
  175. <td><input type="submit" name="Submit" value="Send Message"></td>
  176. </tr>
  177. </table>
  178. </center>
  179. </form>
  180. <?php
  181. }
  182. //}
  183. ?>
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009
Feb 2nd, 2009
1

Re: supplied argument is not a valid

Put this:
PHP Syntax (Toggle Plain Text)
  1. if (!$user_check) {
  2. die('Invalid query: ' . mysql_error());
  3. }
in between this:
PHP Syntax (Toggle Plain Text)
  1. $user_check = mysql_query("SELECT userdb_user_name FROM default_userdb WHERE userdb_user_name='$reciever'");
and this:
PHP Syntax (Toggle Plain Text)
  1. $user_check = mysql_num_rows($user_check);
and tell us what is displayed.
Reputation Points: 128
Solved Threads: 43
Posting Whiz
death_oclock is offline Offline
389 posts
since Apr 2006
Feb 2nd, 2009
0

Re: supplied argument is not a valid

here it is

PHP Syntax (Toggle Plain Text)
  1. Invalid query: Table 'newokul_1.default_userdb' doesn't exist
  2.  

default_userdb exist on newokul_1 database
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009
Feb 2nd, 2009
0

Re: supplied argument is not a valid

thank you very much for the help i checked the name again and miss spelled and it works now, i was doing it all day and missed a letter. many thanks
Reputation Points: 27
Solved Threads: 0
Junior Poster
serdas is offline Offline
148 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: problems with php include
Next Thread in PHP Forum Timeline: edit data in the existing field





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


Follow us on Twitter


© 2011 DaniWeb® LLC