Jump to content

[SOLVED] Simple form extraction.. or so i thought....


Recommended Posts

<?php
   //database inforamtion
     $host      = "stocks"; // Host name
     $username  = "wbennett"; // Mysql username
     $password  = "mysql5"; // Mysql password
     $db_name   = "wbennett"; // Database name
     $tbl_name1 = "flight_webair";
    
      mysql_connect("$host", "$username", "$password")or die("cannot connect");
      mysql_select_db("$db_name")or die("cannot select DB"); 
   
   // Variables 
     $flight_route_out    = $_POST['flight_route_out'];
     $flight_route_return = $_POST['flight_route_return'];
     $date_out            = $_POST['departure_date'];
     $date_return         = $_POST['return_date'];
     $passenger_num       = $_POST['num_of_pass'];
     $one_way             = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first.
    
   //To protect MySQL injection
     $flight_route_out = stripslashes($flight_route_out);
     $flight_route_return = stripslashes($flight_route_return);
     $flight_route_out = mysql_real_escape_string($flight_route_out);
     $flight_route_return = mysql_real_escape_string($flight_route_return);
   
   //Queries
     $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'";
     //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'";
   
   //Execute  query  1
     $result = mysql_query($sql1) or die(mysql_error());
     
 if(mysql_num_rows($result) > 0){       
   
      $query = "SELECT * FROM `flight_webair` WHERE flight_route = '$flight_route_out'";
  $result = mysql_query($query) or die(mysql_error());
  
    while($row = mysql_fetch_array($result)){

	  /// show all the webair data here

	}
  		  
   	 }else{

  echo 'Sorry, couldn\'t find any flights';

 }       
             
   

   mysql_free_result($result);   
     
?>

  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

<?php
   //database inforamtion
     $host      = "stocks"; // Host name
     $username  = "wbennett"; // Mysql username
     $password  = "mysql5"; // Mysql password
     $db_name   = "wbennett"; // Database name
     $tbl_name1 = "flight_webair";
    
      mysql_connect("$host", "$username", "$password")or die("cannot connect");
      mysql_select_db("$db_name")or die("cannot select DB"); 
   
   // Variables 
     $flight_route_out    = $_POST['flight_route_out'];
     $flight_route_return = $_POST['flight_route_return'];
     $date_out            = $_POST['departure_date'];
     $date_return         = $_POST['return_date'];
     $passenger_num       = $_POST['num_of_pass'];
     $one_way             = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first.
    
   //To protect MySQL injection
     $flight_route_out = stripslashes($flight_route_out);
     $flight_route_return = stripslashes($flight_route_return);
     $flight_route_out = mysql_real_escape_string($flight_route_out);
     $flight_route_return = mysql_real_escape_string($flight_route_return);
   
   //Queries
     $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'";
     //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'";
   
   //Execute  query  1
     $result = mysql_query($sql1) or die(mysql_error());
     
 if(mysql_num_rows($result) > 0){       
   
      $query = "SELECT * FROM `flight_webair` WHERE flight_route = '$flight_route_out'";
  $result = mysql_query($query) or die(mysql_error());
  
    while($row = mysql_fetch_array($result)){

	  /// show all the webair data here

	}
  		  
   	 }else{

  echo 'Sorry, couldn\'t find any flights';

 }       
             
   

   mysql_free_result($result);   
     
?>

 

In the curly brace can i write pure html in there? this is what i really need it to do so i can get it to generate not only what the query returned but also stuff like my header, buttons and all my standard page layout. (much like a basic template for the page so it looks consistant.

 

thanks :)

sorry i lost internet for a bit! Okay say i had this:

would i put layout here like this:

 

echo "<html>"

echo "<head>"

 

layout stuff butons other general page stuff etc etc

then the while statement


while($row = mysql_fetch_array($result))
      
    {
      
        echo $row['flight_num']; 
    echo $row['flight_route'];   
        echo $row['arrival_time'];
      
      }
             
       }else{
    
     echo 'Sorry, couldn\'t find any flights';
    
    }       

 

and this would give that layout to both the generated code and the "sorry could not find..." page also...

 

plus is there a quicker way to insert my tempalte rather than going

 

echo ".."

echo ".."

 

thanks alot sorry about the length of my questions

 

 

 

 

Your template doesn't go inside the curly brackets... only things that loop lol.

 

you can use this for html

<?php

$html=<<<HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

HTML;



?>

Your template doesn't go inside the curly brackets... only things that loop lol.

 

you can use this for html

<?php

$html=<<<HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

HTML;



?>

 

great thanks ill give that a whirl!

 

:)

This topic is really getting long.  You're better of trying what phpSensei suggested and posting a new thread with a specific answer.  Not trying to be rude, but I know I wouldn't sit here and read through all that.  :)

This topic is really getting long.  You're better of trying what phpSensei suggested and posting a new thread with a specific answer.  Not trying to be rude, but I know I wouldn't sit here and read through all that.  :)

 

yeah this is getting off topic anyways ill mark this as solved good idea mate  ;)

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.