I am trying to integrate the php and javascript. I send the javascript variable into php variable. And printed it out in the browser using echo command. It outputs the exact same result that I am expecting. I write following command;
<script>
    var p1 ='Lohuti'
</script>
<?php
            $p1="<script>document.write(p1);</script>";
            $db_connection = pg_connect("host=localhost dbname=postgres user=postgres password=admin");
            $sql = "SELECT * FROM public.flood WHERE jamoat= '".$p1."'";
            echo $sql;
            $result = pg_query($db_connection, $sql);
            while ($row = pg_fetch_row($result)) {
               $row[0]
            }
?>
The echo $sql prints outs SELECT * FROM public.flood WHERE jamoat= 'Lohuti'. But this query unable to fetch the data from a database. If I just replace the php variable $p1 with the name Lohuti, It works fine, I can fetch the data. In my case, I am planning to add the dynamic javascript variable into php variable and query the required result. Is there any solution to this type of problem? 
 
    