Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I creating a search option . where user input city name and see a person details who live in that city . Or user can leave blank input to see all person .

I don't see any error in this code . Checked every php validtor , I find . But this don't output anything

     `<?php

       $find_city = $_POST['find']; //form 

         //if user input nothing see all file             

        if (empty($find_city))
        {
            $find_city = 'ALL';
        }

         //directory open

        $dirname = "gimg";
        $dirhandle = opendir($dirname);

        //check directory

        if($dirhandle)
        {
            while (false !== ($file = readdir($dirhandle)))
            {
                if($file != '.' && $file != '..')
                {
                    displayPropertyInfo($file,$find_city);
                }
            }
        }

        //funtion Definitions

        function displayPropertyInfo($img_filename, $find_city)
        {

            $img_name = 'gimg/'.$img_filename;
            $g_img = "<img src='".$img_name."'>";

            //filename type changing from one directory to another

            $g_info = str_replace('.jpg' , '.txt', $img_filename);

            $filename = 'ginfo/'.$g_info;

            $fp  = fopen($filename, 'r');

            $show_grile = 'Y';

           //search function

            while(true)
            {
                $line = fgets($fp);

                if (feof($fp))
                {
                    break;
                }

                $pos = stripos($line, 'City:');

                if ($pos !== false)
                {
                    $city = substr($line,5);
                    $city = trim($city);

                    if ($find_city != 'ALL')
                    {
                        $subpos = stripos($city,$find_city);

                        if($subpos === false)
                        {
                            $show_gril = 'N';
                            break;
                        }
                    }
                }
                //checking 
                $pos = stripos($line,'Name:');

                if ($pos !== false)
                {
                    $name = substr($line, 5);
                    $name = trim($name);
                }

                $pos = stripos($line,'Age:');

                if ($pos !== false)
                {
                    $age = substr($line, 4);
                    $age = trim($age);
                }
                $pos = stripos($line,'Price:');

                if ($pos !== false)
                {
                    $price = substr($line, 6);
                    $price = trim($price);
                }
                $pos = stripos($line,'Description:');

                if ($pos !== false)
                {
                    $description = substr($line, 12);
                    $description = trim(description);
                }

            }

            if($show_gril == 'Y')
            {
                print $g_img;

                print "City: ".$city."<br/>";
                print "Name: ".$name."<br/>";
                print "Age: ".$age."<br/>";
                print "Price: ".$price."<br/>";
                print "Description: ".$description."<br/>";
            }
        }
    ?>
share

Here's the problem line:

$show_grile = 'Y';

The script only outputs anything if $show_gril is set to Y, and the only line that does that misspells the variable name. It should work if you remove the E on the end.

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.