0

Dear All,
im testing out a way to get data from database depending on the drop down selection and displaying the data into a table by using php. now my first issue which is really really frustrating me because i've done this dozens of time is that i get

Notice: Undefined index: place in D:\Xampp\htdocs\EMS2\testgetdrop.php on line 2

yeah i know a miniscule issue but its getting on my nerves as ive been doin coding for the entire day for a week anyway place is defined as i usually define it

$place = mysql_real_escape_string($_POST['place']);

this is my test page:

<?php
    $place = mysql_real_escape_string($_POST['place']);

    if(isset($_POST['place']))
    {   
        require "connection.php";
        $retrieve = mysql_query("SELECT salutation,fname,lname FROM contact WHERE city LIKE %$place%") or die(mysql_error());
        if($retrieve)
        {
            while($rows = mysql_fetch_array($retrieve))
            {
                $salutation = $rows['salutation'];
                $fname= $rows['fname'];
                $lname = $rows['lname'];

                echo 
                "<table>
                    <thead>  
                        <th>Name</th>
                    </thead>
                    <tr>
                        <td>$salutation $fname $lname</td>
                    </tr>
                </table>";
            }
        }
    }
?>
<html>

<body>

<form method="post" action="testgetdrop.php">
    <select name="place">
        <option value="" disabled selected>Choose</option>
        <option value="Petaling Jaya">Petaling Jaya</option>
        <option value="Kuching">Kuching</option>
    </select>
</form>

</body>
</html>

and my other issue is that when a selection is made nothing happens. am i doing something wrong? or is this just not the right way of doing it?

thanks in advance for any help!

sincerely,
frustrated.

2
Contributors
5
Replies
35
Views
3 Years
Discussion Span
Last Post by nadiam
0

Cut line 2: $place = mysql_real_escape_string($_POST['place']);
and write after check isset() (line 4): if(isset($_POST['place']))

Edited by AndrisP

0

ah.. right.. missed that. thanks!

my other issue is that when a selection is made nothing happens.

0

So i changed the page a bit. The drop down list is populated by data from database which is done successfully. Now, when choosing a selection the salutation and name that corresponds to the selection will be displayed in a table but unfortunately that isn't working. any ideas/suggestions is much appreciated.

<form method="post" action="testgetdrop.php">
    <select name="place">
        <option value="" disabled selected>Choose</option>
        <?php
            require "connection.php";
            $retrieve = mysql_query("SELECT city FROM contact") or die(mysql_error());
            while($rows = mysql_fetch_assoc($retrieve))
            {
                echo "<option value=$rows[city]>$rows[city]</option>";
            }
        ?>
    </select>

    <table>
        <thead>
            <th>Name</th>
        </thead>
        <tbody>
            <?php
                if(isset($_POST['place']))
                {
                    $place = mysql_real_escape_string($_POST['place']);

                    $qname = mysql_query("SELECT salutation,fname,lname FROM contact WHERE city = '$place' ") or die(mysql_error());
                    while($row = mysql_fetch_array($qname))
                    {
                        $salutation = $row['salutation'];
                        $fname = $row['fname'];
                        $lname = $row['lname'];

                        echo 
                        '<tr>
                            <td>$salutation $fname $lname</td>
                        </tr>';
                    }
                }   
            ?>
        </tbody>
    </table>
</form>
0

EDIT: I REALIZED THAT I CANNOT DO THIS THIS WAY FOR WHAT I WANT TO DO SO I WILL BE USING AJAX INSTEAD AND SINCE THIS THREAD IS UNDER WEB DEVELOPMENT IT IS STILL VALID. I WILL POST UP WHAT I HAVE SOON IF I HAVE ANY QUESTION(NO DOUBT I WILL) OR JUST TO SHARE. THANKS FOR YOUR TIME.

0

this is what i found on w3school(though i read that w3school is not reliable/verified or smtg) but i havent tested it out yet.

 <script>
    function showUser(str) {
      if (str=="") {
        document.getElementById("txtHint").innerHTML="";
        return;
      } 
      if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      } else { // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.open("GET","add_guest.php?user="+str,true);
      xmlhttp.send();
    }
    </script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.