Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **1st File: DropDown.php**
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "movies";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- echo "<form method=\"post\" action = \"DropDownList.php\">";
- $actlist = "SELECT AID, ANAME FROM actors";
- $aresult = mysqli_query($conn, $actlist);
- echo "<select id=\"dd\" name=\"ddl\">";
- if (mysqli_num_rows($aresult) > 0)
- {
- echo "<option value = \" \" selected>ACTORS</option>";
- while($ares = mysqli_fetch_assoc($aresult))
- {
- $act = $ares["ANAME"];
- $aid = $ares["AID"];
- echo "<option value = ".$aid.">".$aid." ".$act. "</option>";
- //Below you can see the session variable, I used that to pass $aid of selected item from this file to another php file, //though the value got transferred but only the last item in the list is getting transferred even if I select the other item. //That's the problem I am facing
- /*session_start();
- $_SESSION['seVar'] = $aid;
- session_write_close();
- */
- }
- }
- else
- {
- echo "No rows";
- }
- echo "</select>";
- echo $aid;
- echo "<input type=\"submit\" value=\"Submit\"></input>";
- echo "</form>";
- ?>
- </body>
- </html>
- **2nd File: DropDownList.php**
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "movies";
- $onclk =$_POST["$aid"];
- if(isset($onclk))
- {
- echo $onclk; //Here I tried to receive the selected value from DropDown.php file, but unable to do so.
- }
- /*/ Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- $actlist = "SELECT AID FROM actors";
- $aresult = mysqli_query($conn, $actlist);
- session_start();
- $x=0;
- $act = $_SESSION['seVar'];
- echo $act; //It is displaying the last item of the list, doesn't matter which item I select from the drop down list.
- session_write_close();
- mysqli_close($conn);
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement