Jump to content

Save each record into database and then update table for all users


NightWheeler

Recommended Posts

Hello,

Here is my current code:

index.php

<html>
<body>
<form id="hey" name="hey" method="post" onsubmit="return false">
Name:<input type="text" name="name">
<input type="submit" name="submit" value="click">
</form>
<table class="table table-bordered" id="update">
<thead>
<th>Name</th>
</thead>
<tbody>
<script type="text/javascript">
      $("#hey").submit(function() {
          
        $.ajax({
          type: 'GET',
          url: 'response.php',
          data: {   username: $('#name').val()},
          success: function (data) {
            $("#update").prepend(data);
          },
          error: function (xhr, ajaxOptions, thrownError) {
            alert(thrownError);
          }
        });
      });
      
    </script>
</tbody>
</table>

response.php

<?php
$username = $_GET['username'];
echo "<tr>";
echo "<td>$username</td>";
echo "</tr>";
?>

This code works fine, it prints out the rows as what the user enters.

Now what I want to do is, log all these entries to a mySQL database and also, display these rows over the site. i.e., any user who is online, should be seeing this without having to refresh the page too..

Real time updates in a way.

 

How can I achieve that? Thanks!
 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.