-1

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);

        if($dirhandle)
        {
            $gimgs = array();

            while (false !==($file = readdir($dirhandle)))
            {
                if ($file != "." && $file != "..")
                {
                    array_push($gimgs , $file);
                }
            }
        }

        sort($gimgs);

        // I think problem in this foreach 

        foreach($gimgs as $elm)
        {
            displayPropertyInfo($elm, $find_city);
        }

    //funtion Definitions

    function displayPropertyInfo($elm, $find_city)
    {

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

        //filename type changing from one directory to another

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

        $filename = 'ginfo/'.$g_info;

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

        $show_gril = '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/>";
        }
    }
?>
imran
  • 1
  • 1
  • *"I don't see any error in this code . Checked every php validtor , I find . But this don't output anything"* - You're not checking for that undefined variable, validators validate for structure and don't "test" code and don't know that from Adam. Doesn't output anything because you have syntax errors. – Funk Forty Niner Jul 30 '16 at 00:34
  • and this `$_POST['find']` only "you" know if that contains a value or not. – Funk Forty Niner Jul 30 '16 at 00:35
  • wow really bro !!! you have not code php yet , I guess . – imran Jul 30 '16 at 18:15

1 Answers1

0

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.

RamenChef
  • 5,557
  • 11
  • 31
  • 43