Jump to content

[SOLVED] Not gathering data from db


whare

Recommended Posts

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

Link to comment
Share on other sites

<?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)

Link to comment
Share on other sites

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);
        
        }
  
    }    
  
?>

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

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....

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.