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!
 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.