简体   繁体   中英

how to pass value to php thorough POST(Can i do this just with html and php)

<div id="navigation">
       <ul>
         <li><a href="?id=0")><em>Home</em></a></li>
         <li><a href="?id=2")><em>Login</em></a></li>
         <!-- <form method="POST" onclick="form.submit();"> -->

         <select name="state">
         <option value="Genre">Genre</option>
         <option value="Crime and Drama">Crime and Drama</option>
         <option value="Drama and Romance">Drama and Romance</option>
         <option value="Sci-Fi">Sci-Fi</option>
         <option value="Action">Action</option>
         <option value="Adventure">Adventure</option>
         <option value="Adventure/Fantasy">Adventure/Fantasy</option>
         <option value="Action/Adventure/Fantasy">Action/Adventure/Fantasy</option>
         <option value="Action/Sci-fi/Thriller">Action/Sci-fi/Thriller</option>
         </select>
         <!--<input type="submit" value="Submit" name="listsubmit"  id="sub"> -->

         <li><a href="?id=3")><input type="submit" value="submit" name="listsubmit"></a></li>

         <li><a href="?id=1")><em>Contact us<em></a></li>

What i am trying to do here is take selection from dropdown menu and pass that value through $_POSt to my sql select statement and include that movies.php file in div content.

but unfortunateky i am not finding a way to pass var to php file .doesn't know y my $post is not working .Please guide me how to submit my form what should i menntion in action field since it is my nav.php div navigation. i select one option and pass that to movies.php which takes selected option and include that php in div content based on id value for example: this is my content.php

<?php 
        $id= isset($_GET['id'])? $_GET['id'] :0;
          if($id=="1"){
            include 'Store.php' ;
          }
          else if($id=="2"){
            include 'Login.php'; 
          }
          else if($id=="3"){
              include 'movies.php';       
}

Please advice!

Use jQuery AJAX request. You can pass values return content and show it.

Modify your select and form like this.

<form method="POST" action="?id=3">
     <select name="state" onchange="this.form.submit();">
         <option value="Genre">Genre</option>
         <option value="Crime and Drama">Crime and Drama</option>
         <option value="Drama and Romance">Drama and Romance</option>
         <option value="Sci-Fi">Sci-Fi</option>
         <option value="Action">Action</option>
         <option value="Adventure">Adventure</option>
         <option value="Adventure/Fantasy">Adventure/Fantasy</option>
         <option value="Action/Adventure/Fantasy">Action/Adventure/Fantasy</option>
         <option value="Action/Sci-fi/Thriller">Action/Sci-fi/Thriller</option>
     </select>
</form>

Form action needs for sending GET variable id. Inside movies.php now you can use $_POST['state']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM