Jump to content

[SOLVED] Valid Resource Error.


ptolomea

Recommended Posts

I'm helping a friend out with his website we were cruising right along until he made some changes to the file tree. Now we get

mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/p/t/o/ptolomea/html/functions.php on line 4

 

Just to be sure as his files had alot of code in them i built a new set of files and uploaded to my own webspace which is where this error is coming from.

 

This has been bugging me for 2 days now cant make heads or tails everything i try results in the same.

 

Main page (page1.php)

<?php
require_once 'connect.php';
include 'functions.php';
ob_start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="wrapper">
<?php
test();
//echo genExpBarLinks();
?>
</div>
<?php
mysql_close($con);
ob_end_flush(); 
?>
</body>
</html>

 

connect.php

<?php
$con = mysql_connect('DBIP','CIndex','******');
if (!$con){die('Could not connect to database: ' . mysql_error());}
mysql_select_db('CIndex',$con);
?>

 

functions.php

<?php
function test() {
$data = "Select * from Books";
$all = mysql_query($data,$con) or die(mysql_error());
$test = mysql_fetch_array($all);
var_dump($test);
};

?>

 

If i move the data in functions to page1.php i get results. i have tryed all sorts of things including adding "include and/or require_once connect.php" on/infront of every line in functions.php.

 

My only idea is that functions.php file is not being allowed access to the database connection hence the adding/including of the connection file inside.

 

Thanks for any help

-Ptolomea

Link to comment
Share on other sites

<?php
function test() {
   $data = mysql_query("Select * from Books") or die(mysql_error());
   $test = mysql_fetch_array($data);
   var_dump($test);
};

?>

 

thats a shorter method .... try that...  oh by the way what is $con ??? Nothing there suggests its a defined variable..

Link to comment
Share on other sites

Also rather than :

<?php
$con = mysql_connect('DBIP','CIndex','******');
if (!$con){die('Could not connect to database: ' . mysql_error());}
mysql_select_db('CIndex',$con);
?>

Why not just:

<?php
mysql_connect('DBIP','CIndex','******');
mysql_select_db('CIndex');
?>

Link to comment
Share on other sites

$con is defined in connect.php

 

$con = msql_connect( etc...

 

but i will give those a try, couldn't hurt :), i will edit with results

 

 

Edit

now that worked remvoing the $con from the mysql connect and any mysql function calling $con.

 

care to explain why that would work or is $con not within the scope of functions.php?

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.