atholon Posted December 20, 2008 Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/ Share on other sites More sharing options...
redarrow Posted December 20, 2008 Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720104 Share on other sites More sharing options...
xtopolis Posted December 20, 2008 Share Posted December 20, 2008 http://us3.php.net/manual/en/faq.migration5.php What errors are you getting? Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720106 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720114 Share on other sites More sharing options...
xtopolis Posted December 20, 2008 Share Posted December 20, 2008 So that points to an invalid query(but you said they were ok), or being unable to connect to the database. What if you add or die() to your mysql_connect method? mysql_connect('host','user','pass') or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720119 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720120 Share on other sites More sharing options...
trq Posted December 20, 2008 Share Posted December 20, 2008 You might want to actually post some relevent code. Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720125 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720131 Share on other sites More sharing options...
redarrow Posted December 20, 2008 Share Posted December 20, 2008 $GLOBALS['connect'] <<<< missing i think...... Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720136 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 Nope, that is in the config file. Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720137 Share on other sites More sharing options...
redarrow Posted December 20, 2008 Share Posted December 20, 2008 $getPosition = mysql_fetch_array(mysql_query("SELECT * FROM `position` WHERE `sid`='$position',$GLOBALS['connect']")); // Line with warning Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720140 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720143 Share on other sites More sharing options...
trq Posted December 20, 2008 Share Posted December 20, 2008 You should at least attempt some error handling within this GetUserInfo() method. Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720149 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 I will but I need to figure out a better way to do this or find out what is wrong. I can either do globals like I did above or I can just make a class that handles the queries for me. Link to comment https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720193 Share on other sites More sharing options...
atholon Posted December 20, 2008 Author Share Posted December 20, 2008 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 https://forums.phpfreaks.com/topic/137777-php-and-mysql_query/#findComment-720328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.