zer0uk Posted April 3, 2020 Share Posted April 3, 2020 Hello all, Can anyone help me , the below code which creates a drop down list for a user works fine on a desktop but on a mobile seems to be random the course it selects Thanks in advance <?php // database connect include('../db_connect.php'); // We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: login.php'); exit(); } // if submit button selected run code if(isset($_POST['submit'])){ $_SESSION['district'] = $_POST['district']; header('Location: add_d_choice.php'); } ?> <!DOCTYPE html> <html> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <!--Import Google Icon Font--> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <header> <?php include('../menu.php'); ?> </header> <body bgcolor=#fafafa> <br> <br> <div class="container"> <div class="row"> <div class="card col s10 m8 l6 xl4 push-l3 push-m2 push-s1 push-xl4 z-depth-5"> <div class="card-content"> <div class="input-field col s12 m12 l12 xl12"> <form action="add_choice.php" method="POST"> <select name = "district"> <label>Select District you raced at</label> <option value="" disabled selected>Choose your district</option> <option value="Z">Zwift TT - Z</option> <option value="">--------------------</option> <option value="A">Central A</option> <option value="B">East - B</option> <option value="C">Lincolnshire - C</option> <option value="D">Liverpool - D</option> <option value="E">London East - E</option> <option value="F">London North - F</option> <option value="G">London South - G</option> <option value="H">London West - H</option> <option value="J">Manchester - J</option> <option value="K">Midland - K</option> <option value="L">North - L</option> <option value="M">North East - M</option> <option value="N">South East Midlands - N</option> <option value="O">North Midlands - O</option> <option value="P">South - P</option> <option value="Q">South East - Q</option> <option value="R">South Wales - R</option> <option value="S">South West - S</option> <option value="T">Teeside - T</option> <option value="U">West - U</option> <option value="V">Yorkshire - V</option> <option value="W">Scotland - W</option> <option value="Y">National - Y</option> </select> <input class="btn teal accent-4" type="submit" name="submit" value="Submit"> <br> <br> </form> </div> </div> </div> </div> </div> </div> <!-- Javacript --> <script src=https://code.jquery.com/jquery-3.4.1.min.js></script> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script> $(document).ready(function(){ $('.sidenav').sidenav(); $('select').formSelect(); $('.datepicker').datepicker(); $(".dropdown-trigger").dropdown(); }); </script> </body> <footer> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <?php include('../footer.php'); ?> </footer> </html> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 3, 2020 Share Posted April 3, 2020 I don't understand what this means: "seems to be random the course it selects " What is the problem? 1 Quote Link to comment Share on other sites More sharing options...
zer0uk Posted April 3, 2020 Author Share Posted April 3, 2020 sorry .. so if using a mobile and I pick say J Manchester a different option is nearly always picked , does that make more sense? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 3, 2020 Share Posted April 3, 2020 No it does not. If the user clicks on a choice that is the value that should appear in your $_POST array as element 'district' Of course - on many mobiles the screen is so small it would be easy to select the wrong one with my big fingers. Quote Link to comment Share on other sites More sharing options...
zer0uk Posted April 3, 2020 Author Share Posted April 3, 2020 Its not that simple TBH Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 3, 2020 Share Posted April 3, 2020 From the code you presented - yes it is that simple. 1 Quote Link to comment Share on other sites More sharing options...
zer0uk Posted April 3, 2020 Author Share Posted April 3, 2020 see what I mean ? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 3, 2020 Share Posted April 3, 2020 Must be something in the hidden files that I can't see. I took the basics of your script and ran this: <?php session_start(); // If the user is not logged in redirect to the login page... // if submit button selected run code if(isset($_POST['submit'])) { $_SESSION['district'] = $_POST['district']; echo "You have selected ".$_POST['district']; } // output the html now ?> <!DOCTYPE html> <html> <body bgcolor=#fafafa> <br> <br> <form action="test.php" method="POST"> <label>Select District you raced at</label> <select name = "district"> <option value="" disabled selected>Choose your district</option> <option value="Z">Zwift TT - Z</option> <option value="">--------------------</option> <option value="A">Central A</option> <option value="B">East - B</option> <option value="C">Lincolnshire - C</option> <option value="D">Liverpool - D</option> <option value="E">London East - E</option> <option value="F">London North - F</option> <option value="G">London South - G</option> <option value="H">London West - H</option> <option value="J">Manchester - J</option> <option value="K">Midland - K</option> <option value="L">North - L</option> <option value="M">North East - M</option> <option value="N">South East Midlands - N</option> <option value="O">North Midlands - O</option> <option value="P">South - P</option> <option value="Q">South East - Q</option> <option value="R">South Wales - R</option> <option value="S">South West - S</option> <option value="T">Teeside - T</option> <option value="U">West - U</option> <option value="V">Yorkshire - V</option> <option value="W">Scotland - W</option> <option value="Y">National - Y</option> </select> <br><br> <input type="submit" name="submit" value="Submit"> <br> <br> </form> <?php exit(); This worked equally well on my pc and my iphone. So - look for a problem in the JQ perhaps? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.