Topic: WAMP code problem with some MySQL functions

I have been working some with code and have actually begun to get a few things working! Much to my surprise too! However I'm having an issue with a certain line and cannot figure out what is going on! I was hoping that someone would take a look at it and see what you think? I did have to change the way that it was connecting to my (WAMP) MySQL database after reading some of the line information and went online and I was able to get some information that got this got code into action! Thanks in advance for whatever help you are able to give me!!!! Thanks once again! Code--

<?php
define('BUSINESS_NAME', 'Church of “Christ��  In Shallotte, NC');
define('COPYRIGHT_NAME', BUSINESS_NAME);
define('SITE_ADDRESS', 'http://root@localhost/');
define('INTERVIEWS_PATH', '/home/mypsswd /public_html/interviews/');
define('TEACHING_PATH', '/home/mypsswd/public_html/teaching/');
define('IMAGE_PATH', '/home/mypsswd /public_html/uploaded_images/');
define('DIALUP_PATH', '/home/mypsswd /public_html/sermons/dialup/');
define('HIGHSPEED_PATH', '/home/mypsswd /public_html/sermons/highspeed/');
$Server = "localhost";
$Username = "root";
$Pass = "mypsswd";
$DataBaseName = "testsite_xxxxxxxxx ";
// connect PHP to MySQL
$Connection = mysql_connect ($Server, $Username, $Pass) or die ("Connection Denied");
$link = mysql_connect("localhost", "root", "mypsswd");
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

function db_query( $query )
{
global $link;
return mysql_query( $query );
}
function db_fetch_array( $query )
{
global $link;

_ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _
// this line below is the one that is having a problem!
return mysql_fetch_array( $query, MYSQL_ASSOC);
}
?>

This is what I get on my local test server:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\home\public_html\sources\config.php on line 62
Any ideas?  Once again thanks in advance for your help!  I’m new at this MySQL thing and I’m learning PHP as well so that I can better code!

Last edited by Dwayne Whitley (2009-02-07 15:33:21)

Re: WAMP code problem with some MySQL functions

looks like you are trying to pass a Query into db_fetch_array. That functions expects the result resource from your db_query function.

you would need to call it like:

$result = db_query("SELECT * FROM table_name");
$row = db_fetch_array($result);

BTW, it looks like you are building DB abstraction functions. While this is typically a good thing, you may want to learn using PHP's native mysql_ functions. There's a lot more info out there in learning them. Not that you can't do it your way. Just know that when looking up tutorials to use the PHP native functions that your functions reference.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  Thanks for the code!  This is a site that i did not construct;  but our congregation paid to have constructed and i'm just trying to come to grips with what the code does so that i can better understand it!  The problem that i have had is that about 3 yrs ago the site malfunctioned and it cost the congregation a small fortune to have it repaired and we had added 2 more pages to it;  so after that i decided not anymore will we have to pay an outside company to repair our site.  And since then i have been reading books;  going online and hard coding a practice site.  The only problem is that the practice site that i'm learning with has yet to use a MySQL database as then one does;  so i'm breaking down the code and trying to run it on my (WAMP server) and i keep running into problems.  The site in question has an admin part on the host server which i also have the code for and i now believe that i'm going to have to link to the images (which i also have) to get the ( WAMP server ) to continue and read more code.  This is our main site  and is online www.viewtheword.org  and my practice site that is on-line and hard coded is www.cofchristsh.org .  This is mainly a learning project for me and the code that i've asked about here was done by another.  I'm scared that after the first developer originally coded the site;  that the second one did some unnecessary stuff that i don't quite yet understand!  Thanks for your help tremendously!!!
________________________________________________________________________________________________________________________________
                                                               The *WORD* to live by:  To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

I got ya. Taking over an already coded site is def tough. If you got any other questions just ask away!

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  When i use this code:   $result = db_query("SELECT * FROM table_name");
$row = db_fetch_array($result);   The apache server stops working;  but when i change it back to the code i listed;  it just reads the code and gives this warning--   Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\home\public_html\sources\config.php on line 62. 
Any ideas what is going on?

Thanks in advance for any help you or anyone can give me concerning this!
________________________________________________________________________________________________________________________________
                                                        The *WORD* to live by:  To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

Are you changing the query or running is just like I posted. "SELECT * FROM table_name" is just an example of a query. You'll have to use whatever you are actually wanting to query.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  Yes i did and i've tried several things with this site!  I'm a newbe at this type of site coding and it appears to me that this site is dependent on a multitude of files.  It appears that everything runs through the home pg input and builds each pg from that with help from the database.  There is an admin section;  a cpanel section and 4 css stylesheets.  There are so many backend files css, js and php that with the little bit of knowledge that i have;  i'm more than likely going to have to upload these files to a host site to see if i can make them work that way!  I'm not sure how to tie the admin/cpanel and other files together on a local (WAMP) server?  And i cannot help but wonder if it may be a windows os versus a unix host os that may be causing me the problem?  Any ideas?  Thanks for your help and advice!
________________________________________________________________________________________________________________________________
                                                     The *WORD* to live by: To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

yeah, it's just too hard to know what's going on without seeing the full picture.

I guess my question would be... Does the site work on a remote server (your live site) and if so... when you put all the files, etc.. on your local WAMP server do they run as-is? I'm assuming that is what you are having problems with. That it runs remotely but not locally. If so... have you populated your local DB with all the remote info?

not knowing your DB structure, one of the things I see missing is where you tell PHP what DB you are actually connecting to. somewhere you will need to use the command "mysql_select_db($DataBaseName)". That is unless your site uses multiple databases (which I doubt). Not selecting a DB would cause the error you are seeing as well.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  Yes the live site runs on a host server!  It's on a Unix os.  I have the MySQL dump file and have imported them into the MySQL on my (WAMP) server with no problems there.  I also have all the files; everything under public_html off of the host server and as said before the imported MySQL dump files.  There are just so many files and some of them look the same with other names.  The on-line site uses a rte and cms only available to me; the site administrator. It also has a cpanel section where i can access the PHPmyadmin and database info.  I am running everything as it appears to be running online;  but only i'm getting errors!  Probably too much for me considering my level of knowledge at this point;  for me to figure out!  The site domain is www.schofchristsermon.com with a parked domain that points to it also which we go by: www.viewtheword.org  Any ideas would be most appreciated!  Thanks for all your advice!
________________________________________________________________________________________________________________________________
                                                           The *WORD* to live by: To live is *CHRIST*; to die is gain!

Re: WAMP code problem with some MySQL functions

If it runs online then it should run locally. These days the difference between a windows server and a *nix server aren't that different as far as getting things to run. (lots of differences when you start getting into loading it up). The difference has to be in configuration of your WAMP. prehaps some module of Apache is different or mysql is configured differently.

OK.. here's an idea. Is register_globals on or off on your local site? Try turning it on (I think the default is off). you can change that by clicking on the WAMP icon in the toolbar and checking it in the PHP Settings tab. You may have to restart WAMP.. not sure if it does that for you or not.

The other thing I would do if look at your php_info on bother local and remote and compare teh differences. You need to make your local match your remote by changing settings in WAMP.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  I tried some of your ideas!  I cannot quite figure it out;  but when i go onto the remote server and go under file manager in cpanel;  there is a place or directory called Home.  Under the Home directory starts the public_html directory where all the site files are;  other than the MySQL files.  I think that somehow i'm either going to have to set up this same type of Home directory with all it's files that are on the Unix system or bypass it some way to get my files to work on the (WAMP) server.  A lot of my php files refer to home as being a place of input.   Heres an example of one such php file.  I beleive that all the code has to run through these values in order for them to read correctly!  There is another $input = 'prayerlist'; and so on!  The home is on the remote sever somehow and appears that it must be read in order to process the code correctly!   The pages seem to assemble themselves through a process of everything being true and i cannot figure out how to build this home section on the (WAMP) server!  Does this sound right to you?  Like i've said;  i'm a newbe and trying to figure the code scheme out.  If i must have a home section;  would it need to have it's own directory and be seperate from my public_html folder on my (WAMP) server;  and can i download the files from the file manager section of cpanel without hurting the web site that is still in use?  Thanks for all your help!  code example below:

$input = 'home';

    }



if( empty($input) )

{

    $input = 'home';

}
________________________________________________________________________________________________________________________________
                                                                  The *WORD* to live by:  To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

Tank or whoever would like to help,  When i go onto this site that i'm trying to run on my local server;  the structure tree through SmartFtp has a public_html folder that i use to upload all the sermon wmv videos plus it shows all the php files; jscript files; flash intro banner;  images; etc.  And then i have noticed that this site has another folder called www to which it also has all these files mentioned in the public_html folder.  Is there a reason why the same files would reside in two different directory folders on the same site?  Any help would deeply be appreciated!  Thanks in advance!
________________________________________________________________________________________________________________________________
                                                        The *WORD* to live by:  To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

I think your issue is configuration between WAMP and your remote server. We're shooting in the dark by guessing.

The $input variable is what is extracted from your query string which tells your code what to do.

To be honest I think you may be over your head in trying to jump into someone else's (poorly coded) site and try to figure out what is going on. It's like jumping into an airplane and trying to figure out how to fly it. Sure you can hit buttons and maybe make it go up and down, but the best bet is to take a step back and start with step 1. I would start working on your own PHP project and get familiar with the different settings, functions and language. There are some really great PHP/MySQL books out there to show you the right way to do things.

and to your last question... the www is basically a unix version of a shortcut. Alot of webserver include this becuase in the begining people didn't know where their website was kept. so it allow them to click on that and shortcut into the public_html directory.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  I think you are 100 percent correct!  I have been on the remote site studying it and have noticed that there is a third place called home accessable through cpanel/file manager and there is a multitude of files there as well as there are under public_html and the MySQL database files.  And home is listed as one of the input(s)==home; in one of about 4 configphp files.  One thing that i have noticed;  is the fact that most of the good code that i have ever read was commented really well!  This code is not!  I do have some good MySQL database books;  but the problem for me has been trying to figure out how this site applies to the book examples and i cannot find anything that shows me anything that seems to be remotely close to this perticuliar site!  Not to mention my lack of coding experience!  Do most coders/programmers make their own templates or buy them?  And do most coders/programmers hardcode or is there an easier solution to do good valid and clean coding?  *GOD* willing;  i have the time and if its *HIS* will; i would love to learn more and get better so i can more effeciently take care of the churche's web-site where i attend!  Any suggestions are most welcomed!  Thank you very much for all your help;  it is deeply appreciated!!!!
________________________________________________________________________________________________________________________________
                                                           The *WORD* to live by: To live is *CHRIST*;  to die is gain!

Re: WAMP code problem with some MySQL functions

I think most coders *try* smile to make their own layouts. And there are def a group of programmers/coders that are really good on both sides of the fence. I, however, am not one of those. So on different blogs i set up for my personal use I usually end up buying a nice theme and tweaking it to my liking. But as far as client work we have a designer that does all the layouts.

the problem with starting out with a clean slate is that there are 3 basic languages to learn. PHP (or another serverside language), CSS/XHTML and Javascript. then you can even tack on to that SQL if you are using a database (although its not that complex until you really get into it). It's a lot of ground to cover. I've been doing this stuff for years and I realized that I would never be really good unless I picked one to really go deep with and I landed on PHP (JS being VERY similar in coding structure). So I can do frontend stuff but lately I've just been subing out all the CSS/XHTML work.

it's a shame that your code is so poorly put together. I've seen lots of code without comments and things that just looked strange (prob even written alot of it myself smile ). One thing to posible look at is moving your church site to a CMS where everything is allready written. Then you can concentrate on learning how those work and learn front end code. So you can install something like Expression Engine, Text Pattern, Wordpress or any CMS listed in the forums here and begin to port your site over. then you KNOW you have a good codebase, plus a huge resource of the community of the CMS you choose. And there are lots of Expression Engine folks here as well.

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  I really appreciate your time and value your advice as well!  I'm currently learning some php.  I have already learned quite a bit of css;  but i still have  a lot to learn there as well!  And xhtml has been one that i have learned quite a bit of;  but there is still more to learn!  From what i have seen missing around with web desigin is the fact that learning will never cease if someone is to stay in the game!  I think for the time being;  i'm going to concetrate on php first and then eventually work my way to MySQL.  I have an admin section on this site which is a cms if i'm correct in the terminology.  The site's text and images are uploaded and changed through the admin section through a cms.  It uses a rte and once i upload the images and or rewrite the text;  i submit it and it changes from what it was to what i am updating it to.  The sermons are the only files that i upload through SmartFtp in a sermons/highspeed/dialup folder (directory).  When you are referring to a cms;  is it something other than what i'm referring to?  Sorry for all the questions;  but i'm trying to tap into your knowledge a little bit so that i'll be on the right track with things!  If you don't mind;  what is the backend and what is the frontend of a sites configuration?  I had assumed that the back end was the place where you work with the files through an ftp and the frontend being the place on the server that you work with your pages.  I have a feeling that i'm wrong!  Thanks a lot for everything!  And thanks for your patience with me!!!!
________________________________________________________________________________________________________________________________
                                                                   The *WORD* to live by:   To live is *CHRIST*; to die is gain!

Re: WAMP code problem with some MySQL functions

yes, what you are referring to is, by definition, a CMS. However there are companies that specialize in building them like the ones I mention. And the guys writing that code is rock solid and usually have tons of plugins. I just mentioned those becuase you don;t have to worry about someones bad code... and spend your time on something else smile

I dream with an XML intereface

Re: WAMP code problem with some MySQL functions

Tank,  Thanks!!!!
________________________________________________________________________________________________________________________________
                                                              The *WORD* to live by:  To live is *CHRIST*;  to die is gain!