Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:39:02+00:00 2026-06-15T17:39:02+00:00

I have a form where I keep various fields (name, email, comments) in a

  • 0

I have a form where I keep various fields (name, email, comments) in a mysql database, the data is written, but I would like to show data without reloading the page, press the submit button and view the new comment. .

HTML:

<form action="" method="post" id="form">
    <fieldset>
        <input type="hidden" name="noticia_id" value="<?php echo $id;  ?>"><br>
        <p><label>NOMBRE *</label>
        <input type="text" id="nombre" name="usuario"></p>
        <p><label for="email">EMAIL (No se publicará) *</label>
        <input type="text" id="email" name="email"></p>
        <p><label for="comment">COMENTARIO</label>
        <textarea name="comentario" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
        <p><input type="submit" name="submit" id="submit" tabindex="5" value="Enviar " /></p>

    </fieldset>
</form>

PHP:

<?php
if ($_POST) {
    //conectamos a la base  
    $connect=mysql_connect("localhost","root","");  
    //Seleccionamos la base  
    mysql_select_db("mostra",$connect);
    $id=$_POST['noticia_id'];
    $nick=$_POST['usuario']; 
    $email=$_POST['email']; 
    $comentario=$_POST['comentario']; 
    $query = "INSERT INTO comentarios (usuario,email,comentario,noticia_id, fecha) VALUES('$nick','$email','$comentario','$id', NOW())";
    mysql_query($query) or die(mysql_error());

    $query = "UPDATE  noticias SET num_comentarios= num_comentarios+1 where id_noticia='".$id."'";
    mysql_query($query) or die(mysql_error());
}

?>

How do I create a jquery function or an other method to insert this data without having to reload the page?

I’ve looked at tutorials but I can not help me!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:39:03+00:00Added an answer on June 15, 2026 at 5:39 pm

    In your javascript use Jquery to make a AJAX call as such:

    Say you have a php page called url.php which is doing the SQL insertions and that you are passing a parameter called par1 do the following:

    $.ajax({
        url: "ver.php?par1=" + parValue,
        type: 'POST',
        success: function(result) {
            // use the result as you wish in your html here
    }});
    

    then in ver.php do:

    $par1 = $_POST['par1'];
    

    Ok try this code:

    HTML code:

    <fieldset>
        <input type="hidden" name="noticia_id" value="<?php echo $id;  ?>"><br>
        <p><label>NOMBRE *</label>
        <input type="text" id="nombre" name="usuario"></p>
        <p><label for="email">EMAIL (No se publicará) *</label>
        <input type="text" id="email" name="email"></p>
        <p><label for="comment">COMENTARIO</label>
        <textarea name="comentario" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
        <p><input type="button" name="submit" id="submit" onclick="send_data()" tabindex="5" value="Enviar " /></p>
    
    </fieldset>
    
    Javascript Code:
    
    function send_data()
    {
        var usuario = $('#nombre').val();
        var email = $('#email').val();
        var commentario = $('#comment').val();
    
        $.ajax({
        url: "ver.php?usuario=" + usuario + "&email=" + email + "&comentario=" + commentario,
        type: 'POST',
        success: function(result) {
            // use the result as you wish in your html here
        }});
    
    }
    
    PHP Code:
    
    $connect=mysql_connect("localhost","root","");  
    //Seleccionamos la base  
    mysql_select_db("mostra",$connect);
    $nick=$_POST['usuario']; 
    $email=$_POST['email']; 
    $comentario=$_POST['comentario']; 
    $query = "INSERT INTO comentarios (usuario,email,comentario,noticia_id, fecha) VALUES('$nick','$email','$comentario','$id', NOW())";
    mysql_query($query) or die(mysql_error());
    
    $query = "UPDATE  noticias SET num_comentarios= num_comentarios+1 where id_noticia='".$id."'";
    mysql_query($query) or die(mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form, where some fields are looks like rows, so I can add/delete
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I would like to do an algebraic curve fit of 2D data points, but
I have a form and I would like to customise the markup for it.
I have a form that has several fields that are optional. When the mysql
I have a form which sends data to a text file, but I'm trying
I have a form that allows users to paste input, like on StackOverflow. But
I have form where are 2 input fields and then i have dynamic dataTables
i have form with user data to input and javascript ajax to send information
I have form like this : <div id='add_field' class='locbutton'><a href='#' title='Add'>Add</a></div> <div id='remove_field' class='locbutton2'><a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.