whare Posted February 16, 2009 Share Posted February 16, 2009 Hi all Been along time since i have had the need to ask for your assistance but that time has come once again here is my problem First of all I am a MS Flight Sim user so I downloaded a program and php scripting to create a automatic flight reporting and flight tracking system by taking data out of flight sim via another program and directly transmitting it to a php script for storage in a db but before all that happens it has to get the data for the flight and this is where the problems start here is the code <? // functions.php is required to connect to the database as usual require("./config/functions.php"); $query = mysql_query("SELECT * FROM `hp_flights` where flightnumber='".$DATA2."'"); $num_result = mysql_num_rows($query); if ($num_result > 0) { for ($i=0;$i<$num_result;$i++) { $result = mysql_fetch_array($query); echo "1|flightplan\n"; echo $result['departure']."\n"; echo $result['destination']."\n"; echo $result['alternate']."\n"; echo $result['route']."\n"; echo $result['pax']."\n"; echo $result['cargo']."\n"; echo $result['rules']."\n"; echo $result['aircraft']."\n"; } } else { echo "0|Flightnumber not found"; } ?> now the program on my pc will not collect the data from this script (this is the script that came with the program) so to test it i added the following $DATA2 = $_GET['page']; so that i could use a filename.php?page=[flightnumber] just to see if the file worked well im here so i guess it did not work it just keeps displaying the "else" condition so as I am not a very good coder i carnt seem to see the problem so hoping somebody here might be able to or at least point me in the right direction Thanx all Will P.S Love the new look of the site first time I have been back since it changed Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/ Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 what does your functions.php look like? Are you getting any mysql errors? Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763697 Share on other sites More sharing options...
whare Posted February 16, 2009 Author Share Posted February 16, 2009 <?php $DBHost = 'host'; //Your host, usually localhost $DBUser = 'username'; //Your database username $DBPass = 'pass'; //Your database password $DBName = 'dbname'; //The database name you want/have the user system on mysql_connect("$DBHost", "$DBUser", "$DBPass")or die(mysql_error()); mysql_select_db("$DBName")or die(mysql_error()); ?> And to answer your second question no sql errors it just echo's the else comment in the script (it does the same in the program as what i see on the webpage) Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763700 Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 That's because your DB file is wrong. Here's what you need to do. <?php function dbconnect() { Global $DBHost, $DBUser, $DBPass, $DBName, $dbconnect; $DBHost = 'host'; //Your host, usually localhost $DBUser = 'username'; //Your database username $DBPass = 'pass'; //Your database password $DBName = 'dbname'; //The database name you want/have the user system on $db = mysql_connect("$DBHost", "$DBUser", "$DBPass"); if (!$db) { echo "connect: mysql_error()"; exit; } $select_db = mysql_select_db("$DBName","$db"); if (!$select_db) { echo "select: mysql_error()"; exit; return ($dbconnect); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763710 Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 Now for your main file use this: <? // functions.php is required to connect to the database as usual require("./config/functions.php"); $link_id = dbconnect(); $query = mysql_query("SELECT * FROM `hp_flights` where flightnumber='".$DATA2."'"); $num_result = mysql_num_rows($query); if ($num_result > 0) { for ($i=0;$i<$num_result;$i++) { $result = mysql_fetch_array($query); echo "1|flightplan\n"; echo $result['departure']."\n"; echo $result['destination']."\n"; echo $result['alternate']."\n"; echo $result['route']."\n"; echo $result['pax']."\n"; echo $result['cargo']."\n"; echo $result['rules']."\n"; echo $result['aircraft']."\n"; } } else { echo "0|Flightnumber not found"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763712 Share on other sites More sharing options...
whare Posted February 16, 2009 Author Share Posted February 16, 2009 Tried you code change and got an error Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/[REMOVED]/public_html/flight/config/functions.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763724 Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 Tried you code change and got an error Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/[REMOVED]/public_html/flight/config/functions.php on line 21 Ok so did you fill out your variables correctly? $select_db = mysql_select_db("$DBName","$db"); $DBName and $db.... Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763725 Share on other sites More sharing options...
whare Posted February 16, 2009 Author Share Posted February 16, 2009 Just rechecked them they are all correct according to the hosting cpanel I did copy past from the original function file (just the dbinfo as there was no change in that part) as I already knew that it connected with them settings Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763730 Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 Just rechecked them they are all correct according to the hosting cpanel I did copy past from the original function file (just the dbinfo as there was no change in that part) as I already knew that it connected with them settings Hmm try removing the quotes just to see if it works... so just make it ($DBname,$db) Not sure why it won't work for you because I use this file all the time for my projects. Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763735 Share on other sites More sharing options...
whare Posted February 16, 2009 Author Share Posted February 16, 2009 Thats better it connects now solves half the problem lol added the $_Get['page']; to the file again and it got the data with no problem so I will sonsider this part SOLVED However the program the daya goes into the now showing the hidden java that my host puts on all file but that is another problem Thanx alot for all of your help Quote Link to comment https://forums.phpfreaks.com/topic/145466-solved-not-gathering-data-from-db/#findComment-763745 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.