RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4083 | Replies: 7
Reply
Join Date: Apr 2007
Posts: 9
Reputation: tomf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tomf tomf is offline Offline
Newbie Poster

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

  #1  
Apr 29th, 2007
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

function show_login_form($username,$password,$regcode)
{
  ?>
  <h1>Login</h1>

  <p>
   Login by typing your username and password into
   the boxes below and clicking on the 'Login' button.
   Your username must match your IK account username <b>exactly</b>
   and the password <b>must be different</b>.
  </p>

  <form action="login.php" method="post">
   <table border=0 cellpadding=0 cellspacing=0>
    <tr>
     <td align="right">Username:
     <Input type=text name=username value="<?echo stripslashes($username)?>" class=textinput>
     </td>
    </tr>

    <tr>
     <td align="right">Password:
      <Input type=password name=password value="" class=textinput>
     </td>
    </tr>

    <tr>
     <td>&nbsp;</td>
    </tr>

    <tr>
     <td align="right">
      <input type=submit name=submit value="Login">
     </td>
    </tr>
   </table>

  <p>
   If you do not have an account, please click <a href="register.php">here</a>
   to register an account, or if you have a registration code, enter it here:
   <input type=text name=regcode size=5 value="<?echo stripslashes($regcode);?>" class=textinput>.
  </p>

  </form>
  <?
}

function prepare_failed_alert($failedattempts)
 {
  if ($failedattempts == 1)
   {
    $string  = "Warning, there has been a failed attempt ";
   }
  else
   {
    $string  = "Warning, there have been $failedattempts failed attempts ";
   }
  $string .= "to log into your account.";

  $_SESSION['head_message'] .= $string;
 }

function process_groups()
 {
    // now we'll get the group memberships
    $groups="groupfileeveryone";

    // set the session variables for the groups you want to check.  If found it will
    // contain a positive number, if not, it will contain FALSE and the existance of 
    // it can be checked with:
    //
    // if ($_SESSION["variable"])
    //
    $_SESSION['group_all']=strpos($groups,"everyone");
 }

function authenticate($username,$password,$regcode)
 {
    require_once ("usersql.php");

    $loginwhere=$_SERVER['REMOTE_ADDR'];
    $loginwhen=date("Y/m/d H:i:s",time());

    $loginconn=mysql_connect($userhost,$useruser,$userpass);
    mysql_select_db($userdb,$loginconn);

    $query="SELECT * FROM $usertable WHERE username='$username' AND password='$password'";
    $result=mysql_query($query,$loginconn);

    if(mysql_num_rows($result))
     {
      $loginrow=mysql_fetch_array($result);
      $failedattempts=$loginrow['failedattempts'];
      $dbregcode=$loginrow['userreqcode'];
      if ($dbregcode=="")
       {
        $query="UPDATE $usertable SET lastloginwhere='$loginwhere', failedattempts='0',
               lastloginwhen='$loginwhen' WHERE username='$username'";
        $result=mysql_query($query,$loginconn);
        $_SESSION['username']=$myrow['username'];

  process_groups();

        if ($failedattempts > 0)
         {
          prepare_failed_alert($failedattempts);
         }

        if ($regcode != "")
         {
          $_SESSION['alert'] .= "You don't need to enter the registration code any more";
         }
        return true;
       } // end if dbregcode is empty
      else
       {
        if ($dbregcode == $regcode)
         {
           $query="UPDATE $usertable SET userreqcode='', lastloginwhere='$loginwhere',
                  active='1', useractivated='$loginwhen', failedattempts='0',
                  lastloginwhen='$loginwhen' WHERE username='$username'";
           $result=mysql_query($query,$loginconn);

          if ($failedattempts > 0)
           {
            prepare_failed_alert($failedattempts);
           } // end failed attempts

           $_SESSION['username']=$myrow['username'];

  process_groups();


           return true;
         } // end if the regcode matched
        else
         {
          $_SESSION['alert'] = "You need to enter the registration code as well";
          return false;
         } // end if the regcode didn't match
       } // end else not empty
     }
    else
     {
      // let's see if the username was valid
      $query="SELECT * FROM $usertable WHERE username='$username'";
      $result=mysql_query($query,$loginconn);
      if(mysql_num_rows($result))
       {
        $loginrow=mysql_fetch_array($result);
        $failedattempts=$loginrow['failedattempts'];
        $failedattempts++;
        $query="UPDATE $usertable SET failedattempts='$failedattempts'
          WHERE username='$username'";
        $result=mysql_query($query,$loginconn);
       } // end if we found a valid username

      $_SESSION['alert'] = "Invalid Username and Password, please try again";
      return false;
     }
 }
?>


whats the problem?

thanks!
Last edited by tomf : Apr 29th, 2007 at 5:47 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

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

  #2  
Apr 30th, 2007
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.
Reply With Quote  
Join Date: Apr 2007
Posts: 9
Reputation: tomf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tomf tomf is offline Offline
Newbie Poster

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

  #3  
Apr 30th, 2007
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?
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

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

  #4  
Apr 30th, 2007
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
Reply With Quote  
Join Date: Apr 2007
Posts: 9
Reputation: tomf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tomf tomf is offline Offline
Newbie Poster

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

  #5  
Apr 30th, 2007
Ok, thanks
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

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

  #6  
Apr 30th, 2007
anytime dude
Reply With Quote  
Join Date: Apr 2007
Posts: 9
Reputation: tomf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tomf tomf is offline Offline
Newbie Poster

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

  #7  
May 2nd, 2007
Originally Posted by w_3rabi View Post
anytime dude


How do i change the settings in my script?
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

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

  #8  
May 3rd, 2007
you could use [php]ini_set()[/php]
but i advice you to contact the server administrator
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:13 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC