SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP isset - Issue

    Hi Guys,

    I'm doing a query in MySQL and doing if theres data in the row of a field then echo the text out. But for some reason its echoing even if there is no text in the field. Any help would be great, iv checked the database and logged into MySQL Workbench to make sure there was no spaces and theres not but its still echoing the text for some reason.

    PHP Code:
    <?php
    // Quote variable to make safe  
    function quote_smart($value)  
    {  
       
    // Stripslashes  
       
    if (get_magic_quotes_gpc()) {  
           
    $value stripslashes($value);  
       }  
       
    // Quote if not a number or a numeric string  
       
    if (!is_numeric($value)) {  
           
    $value "'" mysql_real_escape_string($value) . "'";  
       }  
       return 
    $value;  
    // end make safe

    $postcode=$_GET["postcode"];

    require(
    "./databaseconnection.php"); //Get Database Login Information

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

    $query sprintf("SELECT * FROM PAF WHERE Postcode LIKE %s",
                
    quote_smart($postcode));
    //echo $query;
    mysql_query($query) or dies(mysql_error()); 
    $result mysql_query($query);

    ?>
    <select name="addressbox" id="addressbox" style="width:285px;" onchange="AddressPicked();">
    <option value="">Select address here...</option>
    <?
    while($row mysql_fetch_array($result))
      {
            
        
    ?>
      <option value="<? echo $row['postcode']; ?>"><?         
            
            
      
      
    if(isset($row['Organisation_Name'])) 
            {
                echo 
    $row['Organisation_Name']. ", ";
            };
            if(isset(
    $row['Building_Name'])) 
            {
                echo 
    $row['Building_Name']. ", ";
            };
            if(isset(
    $row['Building_Number'])) 
            {
                echo 
    $row['Building_Number']. ", ";
            };
            if(isset(
    $row['Dependent_Thoroughfare'])) 
            {
                echo 
    $row['Dependent_Thoroughfare']. ", ";
            };        
            if(isset(
    $row['Thoroughfare'])) 
            {
                echo 
    $row['Thoroughfare']. ", ";
            };
            if(isset(
    $row['Post_Town'])) 
            {
                echo 
    $row['Post_Town']. ", ";
            };
            if(isset(
    $row['Dependent_Locality'])) 
            {
                echo 
    $row['Dependent_Locality']. ", ";
            };
            if(isset(
    $row['Postcode'])) 
            {
                echo 
    $row['Postcode']. " ";
            };
      
      
      
    ?></option>
      <?
      
    }
     
    ?>
     </select>
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    check a var_dump($row['postcode']);
    It may be set but empty.
    If so, use !empty($row['postcode'])

  3. #3
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, the !empty has worked a treat
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •