Jump to content

alanl1

Members
  • Posts

    80
  • Joined

  • Last visited

Posts posted by alanl1

  1. Hi Professionals

     

    I have the following 2 pages, in the welcome.php I am trying to retreive the TowerSelect drop downs value to echo in the page but it is only showing  TowerSelect not the actual value.

     

    Where could I be going wrong

     

     

    thanks

     

     

    <html>
    </body>
    <form action="welcome.php" method="POST">
    Please select the manufacturer you wish to report on. </br></br>

    <select name="TowerSelect"><option> Choose </option>

    <?php
     
    $server='d3licsql02';
    $connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "SECRET");

    //connect to DB
    $conn=sqlsrv_connect($server,$connectinfo);
     
    if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    $sql = "SELECT distinct software_manufacturer FROM softusecomp";
    $sql1 = "SELECT distinct software_manufacturer, product,product_version,path FROM softusecomp";
    $stmt = sqlsrv_query( $conn, $sql);

    if( $stmt === false) {
       die( print_r( sqlsrv_errors(), true) );
    }

    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

    echo "<option value=";
    echo "'".$row['software_manufacturer']."'";
    echo ">";
    echo $row['software_manufacturer'];
    echo "</option>";

    }

    sqlsrv_free_stmt( $stmt);

    ?>
    </select>
      <input type="submit" value="Search">
    </br></br>
    </form>
    </body></html>

    --------------------------------------------------------------------------------------------

     

    <html>
    </body>
    <form action="filter.php" method="POST">
    Report for -Insert manufacturer name here-. </br></br>
    TowerSelect

    <?php

     
    $server='d3licsql02';
    $connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "SECRET");

    //connect to DB
    $conn=sqlsrv_connect($server,$connectinfo);
     
    if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    $manufacturer_name = $_GET['TowerSelect'];

    echo $manufacturer_name;

    $sql = "SELECT top 100 software_manufacturer, product,product_version,path FROM softusecomp where software_manufacturer = 'Microsoft Corporation'";
    $stmt = sqlsrv_query( $conn, $sql);

    if( $stmt === false) {
       die( print_r( sqlsrv_errors(), true) );
    }

    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

    echo $row['software_manufacturer'].", ".$row['product'].", ".$row['product_version'].", ".$row['path']."<br />";

    }

    sqlsrv_free_stmt( $stmt);

    ?>

      <input type="submit" value="filter">
    </br></br>
    </form>
    </body></html>

  2. Hi professionals

     

    Fairly new to php, anyway I have installed php successfully i think and displayed a hello world.

     

    now I am trying to connect to our Sql Server 2008 database but it keeps throwing the error "Error connecting to SQL Server"

     

     

    any ideas where I could be going wrong, could it be the install, do i need to allow sql server to let webpages connect to the db etc I honestly have no idea.

     

    here is the code

     

    <?php
       $serverName = "d3licsql02";
       $database = "TestData";

       // Get UID and PWD from variables.
       $uid = "sa";
       $pwd = "secret";

    echo $serverName;
    echo "<br>";
    echo $database;
    echo "<br>";
    echo $uid;
    echo "<br>";
    echo $pwd;
    echo "<br>";

       try {
          $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd);
          $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
       }

       catch( PDOException $e ) {
          die( "Error connecting to SQL Server" );
       }

       echo "Connected to SQL Server\n";

       $query = 'select * from Postcodes.Suburb';
       $stmt = $conn->query( $query );
       while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
          print_r( $row );
       }

       // Free statement and connection resources.
       $stmt = null;
       $conn = null;
    ?>

  3. ok i can use method post and a text box of input = hidden but my question is actually how do i pass the longtitude which is seleected from the database during the onclick event

     

    as you can see in the while loop in the autosuggesat.php above it is dynamically building the drop down list with a selected value (suburb) from the database

     

     while ($result = $query ->fetch_object()) {
    echo '<li onClick="fill(\''.addslashes($result->suburb).'\');">'.$result->suburb.' '.$result->postcode.' '.$result->state.'</li>';

    }
    echo '</ul>';

     

     

    how do i actually populate the hidden box with the latitude value what the user wouldnt see, could this be done after the while loop if so how

     

     

     

    thanks again

  4. thanks for that I have ammended my page structure to this, but I still not sure how to pass the longtitude and latitude through to the next page without the user seeing them.

     

     

    <!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
        <script>
    function suggest(inputString){
      if(inputString.length == 0) {
       $('#suggestions').fadeOut();
      } else {
      $('#suburb').addClass('load');
      $('#latitude').addClass('load');
       $.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
        if(data.length >0) {
         $('#suggestions').fadeIn();
         $('#suggestionsList').html(data);
         $('#suburb').removeClass('load');
         $('#latitude').removeClass('load');
        }
       });
      }
     }

     function fill(thisValue) {
      $('#suburb').val(thisValue);
      $('#latitude').val(thisValue);
      setTimeout("$('#suggestions').fadeOut();", 600);
     }

    </script>
        <style>
    #result {
     height:20px;
     font-size:16px;
     font-family:Arial, Helvetica, sans-serif;
     color:#222;
     padding:5px;
     margin-bottom:10px;
     background-color:#F0FFFF;
    }
    #suburb{
     padding:3px;
     border:1px #CCC solid;
     font-size:12px;
    }
    #latitude{
     padding:3px;
     border:1px #CCC solid;
     font-size:12px;
    }
    .suggestionsBox {
     position: absolute;
     left: 280px;
     top:40px;
     margin: 26px 0px 0px 0px;
     width: 100px;
     padding:0px;
     background-color: #F0FFFF
     
     border-top: 3px solid #000;
     color: #fff;
    }
    .suggestionList {
     margin: 0px;
     padding: 0px;
    }
    .suggestionList ul li {
     list-style:none;
     margin: 0px;
     padding: 6px;
     border-bottom:1px dotted #666;
     cursor: pointer;
    }
    .suggestionList ul li:hover {
     background-color: #FC3;
     color:#000;
    }
    ul {
     font-family:Arial, Helvetica, sans-serif;
     font-size:11px;
     color:#FFF;
     padding:0;
     margin:0;
    }

    .load{
    background-image:url(loader.gif);
    background-position:right;
    background-repeat:no-repeat;
    }

    #suggest {
     position:relative;
    }

    </style></head>
    <body>
     
    <div id="page-wrap">
      <ul id="main-nav">
       
      <li class="home"><a href="index.php">Post Ad</a></li>
       
      <li class="current"><a href="search.php">Search</a></li>
       
      <li class="signin"><a href="signin.php">Sign in</a></li>
       
      <li class="register"><a href="register.php">Register</a></li>
       
      <li class="about"><a href="about.php">About us</a></li>
       
      <li class="contact"><a href="contact.php">Contact</a></li>
      </ul>
      <div class="clear"></div>
     
    <div id="featured">
      <div id="image">
        <div align="left">
            <img src="images/buy_sell.jpg" alt="buy_sell"/> </div>
      
      </div>
      <div id="featured-content"> </div>
        <h1>Buy and Sell things</h1>
        <br>
        <form method="get" action="find-a-radius.php" >
        <input name="searchfor" type="text" value="Search for" size="20" maxlength="50" />
      <div id="suggest">Postcode or Suburb: <br />
     <input name="suburb" type="text" class="" id="suburb" onblur="fill();" onkeyup="suggest(this.value);" size="25" maxlength="50" /> 

     

      <input type="submit" value="Search">
     
      
         
          
            <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="arrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
              <div class="suggestionList" id="suggestionsList">   </div>
            </div>
          </div>
      
        <br><div class="searchCategory " >
          <select id="select4" name="category"    class="searchFilter">
            <option selected="selected" value="other">Category (select)</option>
            <option value="automotive" >Automotive </option>
            <option value="baby_children" >Baby & Children </option>
            <option value="boating_accesories" >Boating & Accesories </option>
            <option value="caravans_camping" >Caravans & Camping</option>
            <option value="car_sharing_commuting" >Car Sharing - Commuting</option>
            <option value="clothes_accesories" >Clothes & Accesories</option>
            <option value="community" >Community</option>
            <option value="computers_pcs_laptops" >Computers, Pc's & Laptops</option>
            <option value="diy" >DIY</option>
            <option value="farming_livestock_agriculture" >Farming & Livestock
            </option>
            <option value="gaming_videos" >Gaming & Videos</option>
            <option value="garage_sale" >Garage Sale</option>
            <option value="gardening_outdoors" >Gardening & Outdoors</option>
            <option value="health_beauty" >Health & Beauty</option>
            <option value="hobbies_pastimes" >Hobbies & Pastimes</option>
            <option value="holidays" >Holidays</option>
            <option value="home" >Home and Garden</option>
            <option value="jobs_careers" >Jobs & Careers</option>
            <option value="kids_stuff" >Kids Stuff</option>
            <option value="music_instruments" >Music & Instruments</option>
            <option value="office_business" >Office & Business</option>
            <option value="pets" >Pets</option>
            <option value="phones_accesories" >Phones & Accesories</option>
            <option value="property" >Property</option>
            <option value="sports_recreation" >Sports & Recreation</option>
            <option value="weddings" >Weddings</option>
            <option value="other" >Other</option>
            <option value="adult" >Adult</option>
          </select>
          <select name="radius" id="select5" >
            <option selected="selected" value="1" style="width: 30px">Distance
            (select) </option>
            <option value="1">Within 5 kilometers</option>
            <option value="10">Within 10 kilometers</option>
            <option value="20">Within 20 kilometers</option>
            <option value="30">Within 30 kilometers</option>
            <option value="40">Within 40 kilometers</option>
            <option value="60">Within 60 kilometers</option>
            <option value="100">Within 100 kilometers</option>
            <option value="1500">State Wide</option>
            <option value="5000">Country Wide</option>
          </select>
           

        </form>
        </div>
      </div>
    </body>
    </html>

  5. Hi professionals

     

    I have two php webpages shown below and the the problem I am having is I can pass the variable suburb, searchfor, category and radius through no problem to the find-a-radius.php, but I am wanting to pass through the longtitude and latitude co-ordinates from the database to in order for me to do my calculations without them dynamically being seen in the dropdown box by a user

     

    I am sorry if this is a complex post but I am fairly new to php/mysql I do hope there is someone out there who is experienced enough to figure this out

     

    SEARCH.PHP

     

     

    <!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
     
    <div id="page-wrap">
      <ul id="main-nav">
       
      <li class="home"><a href="index.php">Post Ad</a></li>
       
      <li class="current"><a href="search.php">Search</a></li>
       
      <li class="signin"><a href="signin.php">Sign in</a></li>
       
      <li class="register"><a href="register.php">Register</a></li>
       
      <li class="about"><a href="about.php">About us</a></li>
       
      <li class="contact"><a href="contact.php">Contact</a></li>
      </ul>
      <div class="clear"></div>
     
    <div id="featured">
      <div id="image">
        <div align="left">
            <img src="images/buy_sell.jpg" alt="buy_sell"/> </div>
      
      </div>
      <div id="featured-content"> </div>
        <h1>Buy and Sell things</h1>
        <br>
        <form method="get" action="find-a-radius.php" >
        <input name="searchfor" type="text" value="Search for" size="20" maxlength="50" />
      <div id="suggest">Postcode or Suburb: <br />
     <input name="suburb" type="text" class="" id="suburb" onblur="fill();" onkeyup="suggest(this.value);" size="25" maxlength="50" /> 
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
        <script>
    function suggest(inputString){
      if(inputString.length == 0) {
       $('#suggestions').fadeOut();
      } else {
      $('#suburb').addClass('load');
      $('#latitude').addClass('load');
       $.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
        if(data.length >0) {
         $('#suggestions').fadeIn();
         $('#suggestionsList').html(data);
         $('#suburb').removeClass('load');
         $('#latitude').removeClass('load');
        }
       });
      }
     }

     function fill(thisValue) {
      $('#suburb').val(thisValue);
      $('#latitude').val(thisValue);
      setTimeout("$('#suggestions').fadeOut();", 600);
     }

    </script>
        <style>
    #result {
     height:20px;
     font-size:16px;
     font-family:Arial, Helvetica, sans-serif;
     color:#222;
     padding:5px;
     margin-bottom:10px;
     background-color:#F0FFFF;
    }
    #suburb{
     padding:3px;
     border:1px #CCC solid;
     font-size:12px;
    }
    #latitude{
     padding:3px;
     border:1px #CCC solid;
     font-size:12px;
    }
    .suggestionsBox {
     position: absolute;
     left: 280px;
     top:40px;
     margin: 26px 0px 0px 0px;
     width: 100px;
     padding:0px;
     background-color: #F0FFFF
     
     border-top: 3px solid #000;
     color: #fff;
    }
    .suggestionList {
     margin: 0px;
     padding: 0px;
    }
    .suggestionList ul li {
     list-style:none;
     margin: 0px;
     padding: 6px;
     border-bottom:1px dotted #666;
     cursor: pointer;
    }
    .suggestionList ul li:hover {
     background-color: #FC3;
     color:#000;
    }
    ul {
     font-family:Arial, Helvetica, sans-serif;
     font-size:11px;
     color:#FFF;
     padding:0;
     margin:0;
    }

    .load{
    background-image:url(loader.gif);
    background-position:right;
    background-repeat:no-repeat;
    }

    #suggest {
     position:relative;
    }

    </style></head>

      <input type="submit" value="Search">
     
      
         
          
            <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="arrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
              <div class="suggestionList" id="suggestionsList">   </div>
            </div>
          </div>
      
        <br><div class="searchCategory " >
          <select id="select4" name="category"    class="searchFilter">
            <option selected="selected" value="other">Category (select)</option>
            <option value="automotive" >Automotive </option>
            <option value="baby_children" >Baby & Children </option>
            <option value="boating_accesories" >Boating & Accesories </option>
            <option value="caravans_camping" >Caravans & Camping</option>
            <option value="car_sharing_commuting" >Car Sharing - Commuting</option>
            <option value="clothes_accesories" >Clothes & Accesories</option>
            <option value="community" >Community</option>
            <option value="computers_pcs_laptops" >Computers, Pc's & Laptops</option>
            <option value="diy" >DIY</option>
            <option value="farming_livestock_agriculture" >Farming & Livestock
            </option>
            <option value="gaming_videos" >Gaming & Videos</option>
            <option value="garage_sale" >Garage Sale</option>
            <option value="gardening_outdoors" >Gardening & Outdoors</option>
            <option value="health_beauty" >Health & Beauty</option>
            <option value="hobbies_pastimes" >Hobbies & Pastimes</option>
            <option value="holidays" >Holidays</option>
            <option value="home" >Home and Garden</option>
            <option value="jobs_careers" >Jobs & Careers</option>
            <option value="kids_stuff" >Kids Stuff</option>
            <option value="music_instruments" >Music & Instruments</option>
            <option value="office_business" >Office & Business</option>
            <option value="pets" >Pets</option>
            <option value="phones_accesories" >Phones & Accesories</option>
            <option value="property" >Property</option>
            <option value="sports_recreation" >Sports & Recreation</option>
            <option value="weddings" >Weddings</option>
            <option value="other" >Other</option>
            <option value="adult" >Adult</option>
          </select>
          <select name="radius" id="select5" >
            <option selected="selected" value="1" style="width: 30px">Distance
            (select) </option>
            <option value="1">Within 5 kilometers</option>
            <option value="10">Within 10 kilometers</option>
            <option value="20">Within 20 kilometers</option>
            <option value="30">Within 30 kilometers</option>
            <option value="40">Within 40 kilometers</option>
            <option value="60">Within 60 kilometers</option>
            <option value="100">Within 100 kilometers</option>
            <option value="1500">State Wide</option>
            <option value="5000">Country Wide</option>
          </select>
           

        </form>
        </div>
      </div>
    </body>
    </html>

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    AUTOSUGGEST.PHP

     

    <?php

    require("phpsqlsearch_dbinfo.php");

       $db = new mysqli($databasehost,$databaseusername,$databasepassword, $databasename);
     
     if(!$db) {
     
      echo 'Could not connect to the database.';
     } else {
     
      if(isset($_POST['queryString'])) {
       $queryString = $db->real_escape_string($_POST['queryString']);
       
       if(strlen($queryString) >0) {

        $query = $db->query("SELECT suburb,postcode,state,longtitude,latitude FROM Postcode WHERE suburb LIKE '$queryString%' or postcode LIKE '$queryString%' LIMIT 10");
        if($query) {
        echo '<ul>';
         while ($result = $query ->fetch_object()) {
                 echo '<li onClick="fill(\''.addslashes($result->suburb).'\');">'.$result->suburb.' '.$result->postcode.' '.$result->state.'</li>';
          
                }
        echo '</ul>';
         
        } else {
         echo 'OOPS we had a problem :(';
        }
       } else {
        // do nothing
       }
      } else {
       echo 'There should be no direct access to this script!';
      }
     }
    ?>

     

     

     

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