ptolomea Posted June 16, 2009 Share Posted June 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162478-solved-valid-resource-error/ Share on other sites More sharing options...
EchoFool Posted June 16, 2009 Share Posted June 16, 2009 <?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.. Quote Link to comment https://forums.phpfreaks.com/topic/162478-solved-valid-resource-error/#findComment-857577 Share on other sites More sharing options...
EchoFool Posted June 16, 2009 Share Posted June 16, 2009 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162478-solved-valid-resource-error/#findComment-857582 Share on other sites More sharing options...
ptolomea Posted June 16, 2009 Author Share Posted June 16, 2009 $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? Quote Link to comment https://forums.phpfreaks.com/topic/162478-solved-valid-resource-error/#findComment-857585 Share on other sites More sharing options...
EchoFool Posted June 16, 2009 Share Posted June 16, 2009 Yeh i feel connect in the connect area so your not carrying the $con.. once connected the query i showed you will work.. Quote Link to comment https://forums.phpfreaks.com/topic/162478-solved-valid-resource-error/#findComment-857586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.