PHP form stay on same page

Viewed 1210

Hi i am trying to update data in a database from a form on the same page as the php code without redirecting/reloading the page.

I tried this tutorial but that didn't work: http://www.formget.com/form-submit-without-page-refreshing-jquery-php/

Update code:

<?php
include "db.php";
session_start();
$value=$_POST['name'];
$query = mysqli_query($connection,"UPDATE users SET profiel='$value' WHERE username='$_SESSION['user']'");
?>

Profilecomplete.js:

$(document).ready(function() {
    $("#submit").click(function() {
        var name = $("#name").val();
        if (name == '') {
            alert("Insertion Failed Some Fields are Blank....!!");
        } else {
        // Returns successful data submission message when the entered information is stored in database.
            $.post("config/profilecomplete.php", {
                value: name
            }, function(data) {
                alert(data);
                $('#form')[0].reset(); // To reset form fields
            });
        }
    });
});

The form:

<form method="POST" id="form">
    <div class="input-field col s6">
        <input id="name" type="text" class="validate">
        <label for="name">Value</label>
    </div>
    <button type="submit" id="submit" class="btn-flat">Update</button>
</form>
3 Answers
Related