944,181 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 14121
  • PHP RSS
Apr 29th, 2007
0

mysql_query(): supplied argument is not a valid MySQL-Link

Expand Post »
I keep getting some weird errors in this script:
errors:
 Warning:  mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 86

Warning:  mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 87

Warning:  mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 90

Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 92

Warning:  mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 149

Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/ikhelper.freehostia.com/globinc/loginfunc.php on line 150
and the script:


PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. function show_login_form($username,$password,$regcode)
  4. {
  5. ?>
  6. <h1>Login</h1>
  7.  
  8. <p>
  9. Login by typing your username and password into
  10. the boxes below and clicking on the 'Login' button.
  11. Your username must match your IK account username <b>exactly</b>
  12. and the password <b>must be different</b>.
  13. </p>
  14.  
  15. <form action="login.php" method="post">
  16. <table border=0 cellpadding=0 cellspacing=0>
  17. <tr>
  18. <td align="right">Username:
  19. <Input type=text name=username value="<?echo stripslashes($username)?>" class=textinput>
  20. </td>
  21. </tr>
  22.  
  23. <tr>
  24. <td align="right">Password:
  25. <Input type=password name=password value="" class=textinput>
  26. </td>
  27. </tr>
  28.  
  29. <tr>
  30. <td>&nbsp;</td>
  31. </tr>
  32.  
  33. <tr>
  34. <td align="right">
  35. <input type=submit name=submit value="Login">
  36. </td>
  37. </tr>
  38. </table>
  39.  
  40. <p>
  41. If you do not have an account, please click <a href="register.php">here</a>
  42. to register an account, or if you have a registration code, enter it here:
  43. <input type=text name=regcode size=5 value="<?echo stripslashes($regcode);?>" class=textinput>.
  44. </p>
  45.  
  46. </form>
  47. <?
  48. }
  49.  
  50. function prepare_failed_alert($failedattempts)
  51. {
  52. if ($failedattempts == 1)
  53. {
  54. $string = "Warning, there has been a failed attempt ";
  55. }
  56. else
  57. {
  58. $string = "Warning, there have been $failedattempts failed attempts ";
  59. }
  60. $string .= "to log into your account.";
  61.  
  62. $_SESSION['head_message'] .= $string;
  63. }
  64.  
  65. function process_groups()
  66. {
  67. // now we'll get the group memberships
  68. $groups="groupfileeveryone";
  69.  
  70. // set the session variables for the groups you want to check. If found it will
  71. // contain a positive number, if not, it will contain FALSE and the existance of
  72. // it can be checked with:
  73. //
  74. // if ($_SESSION["variable"])
  75. //
  76. $_SESSION['group_all']=strpos($groups,"everyone");
  77. }
  78.  
  79. function authenticate($username,$password,$regcode)
  80. {
  81. require_once ("usersql.php");
  82.  
  83. $loginwhere=$_SERVER['REMOTE_ADDR'];
  84. $loginwhen=date("Y/m/d H:i:s",time());
  85.  
  86. $loginconn=mysql_connect($userhost,$useruser,$userpass);
  87. mysql_select_db($userdb,$loginconn);
  88.  
  89. $query="SELECT * FROM $usertable WHERE username='$username' AND password='$password'";
  90. $result=mysql_query($query,$loginconn);
  91.  
  92. if(mysql_num_rows($result))
  93. {
  94. $loginrow=mysql_fetch_array($result);
  95. $failedattempts=$loginrow['failedattempts'];
  96. $dbregcode=$loginrow['userreqcode'];
  97. if ($dbregcode=="")
  98. {
  99. $query="UPDATE $usertable SET lastloginwhere='$loginwhere', failedattempts='0',
  100. lastloginwhen='$loginwhen' WHERE username='$username'";
  101. $result=mysql_query($query,$loginconn);
  102. $_SESSION['username']=$myrow['username'];
  103.  
  104. process_groups();
  105.  
  106. if ($failedattempts > 0)
  107. {
  108. prepare_failed_alert($failedattempts);
  109. }
  110.  
  111. if ($regcode != "")
  112. {
  113. $_SESSION['alert'] .= "You don't need to enter the registration code any more";
  114. }
  115. return true;
  116. } // end if dbregcode is empty
  117. else
  118. {
  119. if ($dbregcode == $regcode)
  120. {
  121. $query="UPDATE $usertable SET userreqcode='', lastloginwhere='$loginwhere',
  122. active='1', useractivated='$loginwhen', failedattempts='0',
  123. lastloginwhen='$loginwhen' WHERE username='$username'";
  124. $result=mysql_query($query,$loginconn);
  125.  
  126. if ($failedattempts > 0)
  127. {
  128. prepare_failed_alert($failedattempts);
  129. } // end failed attempts
  130.  
  131. $_SESSION['username']=$myrow['username'];
  132.  
  133. process_groups();
  134.  
  135.  
  136. return true;
  137. } // end if the regcode matched
  138. else
  139. {
  140. $_SESSION['alert'] = "You need to enter the registration code as well";
  141. return false;
  142. } // end if the regcode didn't match
  143. } // end else not empty
  144. }
  145. else
  146. {
  147. // let's see if the username was valid
  148. $query="SELECT * FROM $usertable WHERE username='$username'";
  149. $result=mysql_query($query,$loginconn);
  150. if(mysql_num_rows($result))
  151. {
  152. $loginrow=mysql_fetch_array($result);
  153. $failedattempts=$loginrow['failedattempts'];
  154. $failedattempts++;
  155. $query="UPDATE $usertable SET failedattempts='$failedattempts'
  156. WHERE username='$username'";
  157. $result=mysql_query($query,$loginconn);
  158. } // end if we found a valid username
  159.  
  160. $_SESSION['alert'] = "Invalid Username and Password, please try again";
  161. return false;
  162. }
  163. }
  164. ?>

whats the problem?

thanks!
Last edited by tomf; Apr 29th, 2007 at 5:47 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tomf is offline Offline
9 posts
since Apr 2007
Apr 30th, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

looks like the problem is not in the code it self but in configurration
the first error about the mysql connection socket
you should check mysql for the socket and check that it is the same one used in php.ini
Last edited by w_3rabi; Apr 30th, 2007 at 6:46 am.
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Apr 30th, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

Im new to PHP, and im using a free web hosting service.
What socket should it be, and how can i find the PHP.ini?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tomf is offline Offline
9 posts
since Apr 2007
Apr 30th, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

you should check the hosting company for mysql and php settings and it looks the error is not in your code it is just in server configuration
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Apr 30th, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

Ok, thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tomf is offline Offline
9 posts
since Apr 2007
Apr 30th, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

anytime dude
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
May 2nd, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

Click to Expand / Collapse  Quote originally posted by w_3rabi ...
anytime dude
How do i change the settings in my script?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tomf is offline Offline
9 posts
since Apr 2007
May 3rd, 2007
0

Re: mysql_query(): supplied argument is not a valid MySQL-Link

you could use [php]ini_set()[/php]
but i advice you to contact the server administrator
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Nov 18th, 2009
0

correct query

<?php
if(isset($_FILES['file']))
{
if ((($_FILES[
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shundeep is offline Offline
1 posts
since Nov 2009

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: Echo array
Next Thread in PHP Forum Timeline: adding cron job with php ajax





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


Follow us on Twitter


© 2011 DaniWeb® LLC