Jump to content

Recommended Posts

I searched the forums and I checked out the tutorials and honestly I'm totally lost. In an attempt to do this myself because i need to learn PHP I figured I'd post this here vs giving up and heading straight to the freelance forum (where I'll likely end up anyways)

 

Anyhoo. My issue is I am trying to call information via php from one application to display in a CMS application installed in another directory. The code that i have works fine if I install the page in the same directory but I get a mysql fetch array error when I try the same code with the correct path to the config includes.

 

Here is what i have to attempt to bridge the two which I call community_connect.php

 <?php

session_start();

$sitetabs = $_SESSION['sitetabs'];

//define('prdMAINLOCATION', $_SERVER['DOCUMENT_ROOT'].'/umag/');





define('DBSERVER','localhost');

define('DATABASENAME','app1dbname');

define('USERNAME','user');

define('PASSWORD','password');

define('SOCIALDB', 'app2dbname');



mysql_select_db(DATABASENAME);


?>

 

In the area that I wish to place the code from app2 into app1 I put this

<?php
session_start();

include("community_connect.php");

?>
<table border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>

<?php
     $sql="select * from video_members where featured = '1' order by id desc limit 0,3";
     $res=mysql_query($sql);
     while($data_set=mysql_fetch_array($res))
     {
?>
<td width="33%">
<p align="center">
<a href='view_video.php?id=<?=$data_set["id"]?>'>
<img border='0' src='<?=$data_set["video_thumbnail"]?>' width='90' height='67'>
</a>
<br>
<a href='view_video.php?id=<?=$data_set["id"]?>'>
View Video
</a>
</td>
<?php
     }
?>
</tr>
</center>

</table>

 

I get this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/develub/public_html/umag/modules/mod_php/tmp/htmltX22FW on line 9

 

This code worked perfectly while both applications were in the same directory the only difference being rather than include community_connect.php it was include config.php

 

when i attempt to include config.php with the correct directory path to the file I get

Warning: main(home/develub/public_html/includes/config.php) [function.main]: failed to open stream: No such file or directory in /home/develub/public_html/umag/modules/mod_php/tmp/htmleofpGA on line 3

Warning: main() [function.include]: Failed opening 'home/develub/public_html/includes/config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/develub/public_html/umag/modules/mod_php/tmp/htmleofpGA on line 3

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/develub/public_html/umag/modules/mod_php/tmp/htmleofpGA on line 9

    * «
    * 01
    * »
    * Pause

 

I really have NO IDEA what else to try at this point or what the issue is as I have a difficult time even reading php let alone knowing what some of that stuff even means.

 

BUT I MUST learn PHP.. so here I am hoping not to have someone do it for me but explain whats wrong and why its doing and perhaps what i need to do to correct it.

 

Thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/48264-extreme-newbie-to-php-mysql-fetch-error/
Share on other sites

Make sure you update

include("community_connect.php");

to the correct path

 

failed to open stream

 

means it can't find the file used on that line

 

 

 

thanks for responding :)

I have community_connect located in the same directory?

 

I went in and put the full path to community_connect.php to try it out and got this error

Warning: main(home/develub/public_html/umag/community_connect.php) [function.main]: failed to open stream: No such file or directory in /home/develub/public_html/umag/modules/mod_php/tmp/htmlH5gxQB on line 3

Warning: main() [function.include]: Failed opening 'home/develub/public_html/umag/community_connect.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/develub/public_html/umag/modules/mod_php/tmp/htmlH5gxQB on line 3

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/develub/public_html/umag/modules/mod_php/tmp/htmlH5gxQB on line 9

 

community_connect.php is located in the umag directory where as the application i'm trying to pull from is located in the root.

my bad i re-read the error include("community_connect.php"); is fine

 

its used on line 3 of includes/config.php.

 

 

 

right, whew I thought i was losing my mind.

 

I dont have config.php set as the includes because i get a ton of errors vs the community_connect where I get the mysql fetch error.

 

I'm not sure where or how I am supposed to be putting in there to tell it to pull the code from the socialdb which is defined in community_connect.php

 

 

if your re-building the community_connect.php  from parts of the config.php then your need the part mysql_connect or mysql_pconnect

 

I'm not we switched our front end from wordpress to joomla and I took the community connect from how we linked those two.. for some reason its not working in a joomla php enabled module though.

 

I went into the config file and added that section in

 

<?php
$hostname="localhost";
$dbuser="user";
$dbpass="password";
$link = mysql_pconnect($hostname, $dbuser, $dbpass)
or Die("could'nt connect to my sql database");
$select_database = mysql_select_db("develub_amigos", $link)
or Die("could'nt select database");

 

 

and i still get this error message

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/develub/public_html/umag/modules/mod_php/tmp/htmlJC1ylS on line 10

 

 

Could it have to do with this line?

while($data_set=mysql_fetch_array($res))

OK, do you have phpMyAdmin Installed ?

if so can you test the SQL statement to check its valid ?

 

or even

<?php
$hostname="localhost";
$dbuser="user";
$dbpass="password";
$link = mysql_pconnect($hostname, $dbuser, $dbpass)
or die("could'nt connect to my sql database ".mysql_error());
$select_database = mysql_select_db("develub_amigos", $link) or 
die("could'nt select sql database ".mysql_error());
or Die("could'nt select database");
$sql="select * from video_members where featured = '1' order by id desc limit 0,3";
$result = @mysql_query($sql, $link) or
            die("could'nt query '$sql' ".mysql_error());
?>

 

this should help find the error

OK, do you have phpMyAdmin Installed ?

if so can you test the SQL statement to check its valid ?

 

or even

<?php
$hostname="localhost";
$dbuser="user";
$dbpass="password";
$link = mysql_pconnect($hostname, $dbuser, $dbpass)
or die("could'nt connect to my sql database ".mysql_error());
$select_database = mysql_select_db("develub_amigos", $link) or 
die("could'nt select sql database ".mysql_error());
or Die("could'nt select database");
$sql="select * from video_members where featured = '1' order by id desc limit 0,3";
$result = @mysql_query($sql, $link) or
            die("could'nt query '$sql' ".mysql_error());
?>

 

this should help find the error

 

yes I have phpmyadmin

 

this is what it returned

 

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/develub/public_html/umag/modules/mod_php/tmp/htmlcjQkuz on line 2

 

???

 

I'm a bit better at mysql than i am php but the code worked fine as long as it was in the same directory.

try

<?php
$hostname="localhost";
$dbuser="user";
$dbpass="password";
$link = mysql_pconnect($hostname, $dbuser, $dbpass) or 
die("could'nt connect to my sql database ".mysql_error());
$select_database = mysql_select_db("develub_amigos", $link) or 
die("could'nt select sql database ".mysql_error());
$sql="select * from video_members where featured = '1' order by id desc limit 0,3";
$result = @mysql_query($sql, $link) or
            die("could'nt query '$sql' ".mysql_error());
?>

 

 

the code worked fine as long as it was in the same directory.

 

this is why i think its a file not being included.

only real way is to check

try

<?php
$hostname="localhost";
$dbuser="user";
$dbpass="password";
$link = mysql_pconnect($hostname, $dbuser, $dbpass) or 
die("could'nt connect to my sql database ".mysql_error());
$select_database = mysql_select_db("develub_amigos", $link) or 
die("could'nt select sql database ".mysql_error());
$sql="select * from video_members where featured = '1' order by id desc limit 0,3";
$result = @mysql_query($sql, $link) or
            die("could'nt query '$sql' ".mysql_error());
?>

 

 

the code worked fine as long as it was in the same directory.

 

this is why i think its a file not being included.

only real way is to check

 

the only other includes that would be on the original page are top.php and nav.php both of which we wouldn't be using since we're just placing video thumbnails into a module in joomla.

 

I tried the above code and got the same fetch array error. {$res} what is it looking for there?

 

This is mad frustrating :( I really appreciate you tryin to help me out here.

in looking at config.php it says this

 

$site_url="http://www.mysite.com/";
global $file_location;
$file_location="/home/develub/public_html/cookies/";


$site_location="http://www.mysite.com/";
$site_location1="http://www.mysite.com/";

 

since I'm pulling from this in the directory mysite.com/umag is that maybe whats causing the issue as its looking for whatever its looking for in the site location?

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.