Jump to content

PHP and mysql_query()


atholon

Recommended Posts

hey there,

 

So I have been using an older version of PHP and mySQL and I tried uploading my site to a server with PHP5 and the newest version of mySQL...it seems like the link isn't being carried over to the other pages unless I specify it. Is this just due to the php version?

 

I had just been using a config file for the default link and I've used that to determin the connection. On the actual server it won't let me.

Link to comment
Share on other sites

interesting sometimes you need to put a / foward slash in front of the /diretory_file_name.php

 

 

<?php

include("/database_connection.php");

?>

 

no it not a php5 thing it a server config setting.

 

as you can see if you can include a file using the following method your need to also change all your link settings

 

 

 

Link to comment
Share on other sites

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/digitalh/public_html/includes/GetUserInfo.php on line 14

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/digitalh/public_html/includes/MasterPage.php on line 21

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/digitalh/public_html/index.php on line 36

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/digitalh/public_html/index.php on line 37

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/digitalh/public_html/index.php on line 54

 

 

Thing is that they are valid....I checked them in SQL. I am not having issues with the require .... it works on my dev machine but not my webserver .

 

My site is www.digitalhelpfiles.com

Link to comment
Share on other sites

When I do that in the config file nothing happens. When I do a die in these other files with the warnings, it says no database has been selected for those queries.

 

The query worked when I installed using my install script... but none of those other pages that are rendered together with my config.php file take it.

 

The way it is set up is like this:

 

index.php requires MasterPage

MasterPage requires site_common.php

SiteCommon requires many different pages...the first of which is the config.php

some of those pages are strictly classes as well.

GetUserInfo.php is required in site_common.php

 

Link to comment
Share on other sites

GetUserInfo.php:

<?php
  class GetUserInfo
  {   
    var $permission;      
    function GetUserInfo($userName)
    {
      $baseQuery = mysql_query("SELECT * FROM `staff` WHERE `name`='$userName'", $GLOBALS['connect']);

      $getStaffInfo = mysql_fetch_array($baseQuery);
      $position = $getStaffInfo["position"];
      $getPosition = mysql_fetch_array(mysql_query("SELECT * FROM `position` WHERE `sid`='$position'")); // Line with warning
      $this->permission = $getPosition["permission"];           
    }
  }
?>

Link to comment
Share on other sites

Right...BUT....according to PHP documentation, you do not need to do that.

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.

Link to comment
Share on other sites

Here is a little bit better version:

<?php
  class GetUserInfo
  {   
    var $permission;      
    function GetUserInfo($userName)
    {
      $this->permission = 0;
      if(isset($userName))
      {      
        $baseQuery = mysql_query("SELECT * FROM `staff` WHERE `name`='$userName'") or die ("<br />Error in MySQL-query: ".mysql_error());
        if (mysql_num_rows($baseQuery) > 0)
        {
          $getStaffInfo = mysql_fetch_array($baseQuery);
          $position = $getStaffInfo["position"];
          $positionQuery = mysql_query("SELECT * FROM `position` WHERE `sid`='$position'") or die ("<br />Error in MySQL-query: ".mysql_error());
          if (mysql_num_rows($positionQuery) > 0)
          {
            $getPosition = mysql_fetch_array($positionQuery);
            $this->permission = $getPosition["permission"]; 
          }  // End position query
        } // End check for staff query          
      }  // End check for user name    
    } // End GetUserInfo()
  } // End of class
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.