Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show data from database without refreshing the page using jquery, PHP
    primarykey
    data
    text
    <p>Is there anyway to load the newly inserted rows to the database without refreshing the page using jQuery? I am able to send the data to the database without refreshing using jquery but I am stuck at showing that data back without refreshing the page. How do I display the data from the table without refreshing page and make it appear under the table in index.php which I have to display the retrieved data? Thanks </p> <p>This is my index.php</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#submit').click(function(){ $.ajax({ type: "POST", url: 'send.php', data: "user=" + $('#user').val() + "&amp;comment=" + $('#comment').val(), success: function(data){ $('input[type=text]').val('') $('#status').html(data); } }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;input type="text" name="user" id="user"&gt; &lt;input type="text" name="comment" id="comment"&gt; &lt;input name="submit" type="submit" id="submit"&gt; &lt;div id="status"&gt;&lt;/diV&gt; &lt;/div&gt; &lt;br&gt; &lt;?php $con=mysqli_connect("localhost","root","","user"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM comments"); echo "&lt;table width='640' &gt; &lt;tr&gt; &lt;/tr&gt;"; while($row = mysqli_fetch_array($result)) { echo "&lt;tr &gt;"; echo "&lt;td style='vertical-align:text-top'&gt;" . $row['user'] . "&lt;/td&gt;"; echo "&lt;td&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;" . wordwrap($row['comment'], 90, '&lt;br&gt;',true) . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysqli_close($con); ?&gt; </code></pre> <p>And here is my send.php which submits the data to the table.</p> <pre><code>&lt;?php $mysqli = new mysqli("localhost", "root", "", "user"); if ($mysqli-&gt;connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error; } $username = $_POST["user"]; $comment = nl2br($_POST['comment']); $stmt = $mysqli-&gt;prepare("INSERT INTO comments (user, comment) VALUES (?,?)"); $stmt-&gt;bind_param('ss', $username, $comment); $stmt-&gt;execute(); echo"comment posted successfully"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload