tellyphp Posted July 15, 2014 Share Posted July 15, 2014 <?php // create_user.php $username = $_POST['username']; $password = $_POST['user_pass']; $ss_name = $_POST['ss_name']; echo "ss_name: ". $ss_name. "<br/>"; ?> <!-- registration_page.php --> <form method="post" action="create_user.php"> <datalist id = "oecs_systems"> <?php include_once 'db_connect.php'; /*establish databse connection and create mysql object called msql2 */ if ($stmt = $mysqli_obj2->prepare("SELECT ss_name FROM ss_systems ORDER BY ss_name")){ $stmt->execute(); // Execute the prepared query. $stmt->store_result(); $stmt->bind_result($ss_name); while($stmt->fetch()){ echo "<option value=\" $ss_name\">"; } } else{ echo "Error in preparing database statement to display Social Security Systems <br/>"; } ?> </datalist> <label for = "ss_name"> Social Security Organization:</label> <input id = "ss_name" list = "oecs_systems"/> <br> <input name="Button" type="submit" value="Create user account" /> </form> ?> I create a data list in my source file registration_page.php. However when this page then invokes "create_user.php", the "ss_name" id used for the data list echoes nothing to the screen as if nothing was selected. Why can't I read the datalist selection? I have added the code s well Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted July 15, 2014 Share Posted July 15, 2014 You need to give the ss_name input field a name attribute in order to retrieve the selected value when the form is submitted. <input id="ss_name" name="ss_name" list="oecs_systems"/> <br> Quote Link to comment Share on other sites More sharing options...
tellyphp Posted July 16, 2014 Author Share Posted July 16, 2014 Thank you so much. It worked by adding the "name" attribute. For some reason, I thought I read somewhere that the "id" attribute was the replacing the use of the "name" attribute so both are note needed, but in this case it really works!. Thanks so much. Telly Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 16, 2014 Share Posted July 16, 2014 If you are posting the form like normal, the "name" attribute is ALWAYS required or the script won't interpret the input at all. 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.