Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="row">
- <div class="col-md-6">
- <label>Change Favorite Sport</label>
- </div>
- <div class="col-md-6">
- <button type="button" id="change_sport_btn" class="btn btn-primary btn-sm" data-toggle="collapse" data-target="#change_sport_form">Change</button>
- <div class="collapse" id="change_sport_form">
- <form method="post" id="some_id">
- <select name="select_fav_sport" class="form-control">
- <?php
- $sql = mysqli_query($conn, "SELECT sport_name FROM sport");
- while ($row = $sql->fetch_assoc()){
- echo "<option value="{$row['sport_name']}">{$row['sport_name']}</option>";
- }
- ?>
- </select>
- </form>
- </div>
- </div>
- </div>
- $(document).ready(function() {
- $('select[name="select_fav_sport"]').change(function() {
- var select_fav_sport = $(this).val();
- $.ajax({
- url: "update_fav_sport.php",
- method: "POST",
- data: {
- select_fav_sport: select_fav_sport
- },
- success: function(data) {
- $('#some_id').html(data);
- }
- });
- });
- include '../db_connect.php';
- if(isset($_POST["select_fav_sport"]))
- {
- $query = "INSERT INTO users(fav_s) VALUES ('select_fav_sport')";
- $statement = $conn->prepare($query);
- $statement->execute(array('fav_s' => $_POST["select_fav_sport"]));
- $count = $statement->rowCount();
- if($count > 0)
- {
- echo "Favorite sport set Successfully..!";
- }
- else
- {
- echo "Data Insertion Failed";
- }
- }
- else
- {
- echo "unknown index: 'select_fav_sport'";
- }
- $server = "localhost";
- $user = "root";
- $password = "";
- $db = "authentication";
- $conn = new mysqli($server, $user, $password, $db);
- if ($conn-> connect_error){
- die("Connection Error!" . $conn-> connect_error);
- }
Add Comment
Please, Sign In to add comment