Jump to content


Photo

**solved** Retrieving data from mysql dbase query


  • Please log in to reply
2 replies to this topic

#1 Pittlimey

Pittlimey
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 April 2006 - 07:11 PM

I have checked the mysql query... using mysqladmin, it works fine... I can create and put data into the database no problem... but this retrieval query is driving me nuts...

I am trying to retrieve one row, and one only from the database, comparing data from a specific column.

it should be easy... but I cannot figure out what I am doing wrong...

any help would be greatly appreciated...

<code>
<?PHP

$cfgProgDir = 'mypages/';

include($cfgProgDir . "secure.php");


?>

<html>

<head>
<title></title>
</head>
<body>
<form name="ice" action="testing.php" method="post">
<input type="button" value="N Number" onClick="submit" id="getinfo" />
<input type="text" name="n_number" size= "8" maxlength="8"value="" id="n_number" name="n_number" />
</body>
</html>


<?

if (isset($_POST['getinfo']))
{


$Ron=$_POST['ron'];
$N_Number=$_POST['n_number'];
$FleetType=$_POST['fleettype'];
$FlightNumber=$_POST['flightnumber'];

$query = "SELECT FleetType, FlightNumber, Ron, FROM `AircraftInfo` WHERE `N_Number` = '$n_number'" ;


$result = mysql_query($query);



echo "<b><center>Database Output</center></b><br><br>";



$Ron=mysql_result($result,$i,'ron');
$N_Number==mysql_result($result,$i,'n_number');
$FleetType==mysql_result($result,$i,'fleettype');
$FlightNumber==mysql_result($result,$i,'flightnumber');

echo "<b>Fleet Type: $fleettype</b><br>Flight Number: $flightnumber</b><br><b>Ron: $ron</b><br><b>N Number: $n_number</b><br><br><hr><br>";



}

?>
</code>




#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 April 2006 - 07:34 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if (isset($_POST['getinfo'])) [/quote]

You don't have a form element whose name is 'getinfo' so the code never executes.

Similarly, you don't POST anything named 'ron', 'fleettype' or 'flightnumber', so you may as well remove

$Ron=$_POST['ron'];
$FleetType=$_POST['fleettype'];
$FlightNumber=$_POST['flightnumber'];


Change button code to

<input type="submit" value="N Number" name="getinfo" />

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Pittlimey

Pittlimey
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 April 2006 - 01:24 PM

[!--quoteo(post=368110:date=Apr 24 2006, 03:34 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 24 2006, 03:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You don't have a form element whose name is 'getinfo' so the code never executes.

Similarly, you don't POST anything named 'ron', 'fleettype' or 'flightnumber', so you may as well remove

$Ron=$_POST['ron'];
$FleetType=$_POST['fleettype'];
$FlightNumber=$_POST['flightnumber'];
Change button code to

<input type="submit" value="N Number" name="getinfo" />
[/quote]

Barand, thanks for the help, here is a working version just in case anyone else can benefit.
<?PHP
        $cfgProgDir =  'phpSecurePages/';

        include($cfgProgDir . "secure.php");

    

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

    <head>
        <title></title>
    </head>
    <body>
<form name="ice" action="testing.php" method="post">
<input type="submit" value="N Number" name="getinfo" />
<input type="text" name="n_number" size= "8" maxlength="8"value="" id="n_number" name="n_number" />
            </body>
</html>


<?

if (isset($_POST["getinfo"])) 
{

$N_Number=$_POST['n_number'];


$sql = "SELECT `FlightNumber`,`FleetType`,`Ron` FROM `AircraftInfo` WHERE `N_Number` = '$n_number' LIMIT 0, 30 ";
$result = mysql_query($sql);

while($extract = mysql_fetch_array($result))
{
     $fleettype = $extract['FleetType'];
     $flightnumber = $extract['FlightNumber'];
     $Ron = $extract['Ron'];
     $N_Number = $extract['N_Number'];
}

echo "<b><center>".$fleettype.$flightnumber.$Ron.$n_number."</center></b><br><br>";


echo "<b><center>Database Output</center></b><br><br>";



$Ron=mysql_result($result,$i,'Ron');
$N_Number=mysql_result($result,$i,'N_Number');
$FleetType=mysql_result($result,$i,'FleetType');
$FlightNumber=mysql_result($result,$i,'FlightNumber');

echo "<b>Fleet Type: $FleetType</b><br><b>Flight Number: $FlightNumber</b><br><b>Ron: $Ron</b><br><b>N Number: $N_Number</b><br><br><hr><br>";



}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users