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

  • Home
  • SEARCH
  • 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 6793959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:09:51+00:00 2026-05-26T18:09:51+00:00

I want to add a record dynamically. When I insert action = add.php for

  • 0

I want to add a record dynamically.
When I insert action = “add.php” for my form, the addition is accomplished by displaying a message after refreshing.
I want to add this addition without refreshing dynamically.

Also, for the ID of my games, I want that when I delete a record, for the ID to be decremented or removed. So that, when I add a game again, it uses the next ID available, not keeps on incrementing, like it is happeneing with me now.

If I take off add.php from action, nothing happens and the game isn’t added.
My question is, where is this script broken? Or if add.php is not functioning right?

Here is my index.php and add.php

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
     <title>title</title>
</head>
 <body>
 <?php
include("dbconfig.php");
$sql = "SELECT * FROM games";
$result = mysql_query($sql);
while ($record = mysql_fetch_array($result)){

  echo "<p class=\"p" .$record['ID']. "\"></br> Game ID: " .$record['ID']. "</br> Game Name: " .$record['Name'].
  "<br /> Game Type: ".$record['Type']. "<br /> Rating: ".$record['Rating']."<br />  Year Released: ".$record['Release Year']."<br /> <br />" ?>
 <a href="#" id="<?php echo $record["ID"]; ?>" class="deletebutton"><img  src="trash.png" alt="delete"/> </a></p>
<?php
 }
?>

 <form name="add" id ="add" action=""  method="post">
 <input class ="gameID" type="hidden" id="ID" name="ID" value = " ' .$record['ID'] . ' " />
 <b>Game Name: </b> <input type="text" id="name" name="name" size=70>
 <b>Game Type:</b> <input type="text" id="type" name="type" size=40>
 <b>Rating: </b> <input type="number"  id="score"  name="score" min="1.0" max="10.0"  step ="0.1"/>
 <b>Year Released: </b> <input type="number"  min="1900" max="2011" id="Yreleased" name="Yreleased" value="1985" size=4>
 <p><input type="submit" name="Submit" id = "Submit" value="Add Game" class = "add games"></p>
 </form>

 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
 <script type = "text/javascript">
  $(document).ready(function(){

        $("#add").submit(function(){


                        var name =    this['name'].value;
                        var type =    this['type'].value;
                        var rating =  this['score'].value;
                        var release = this['Yreleased'].value;
                        var dataString = 'name='+ name + '&type=' + type + '&rating=' + rating + '&release=' + release;

                    if (name == '' || type == '' || rating == '' || release == ''){
                        alert("please enter some valid data for your game entry");
                    }else
                    $.ajax({
                         type: "POST",
                         url: "add.php",
                         data: dataString,
                         success: function(){
                           window.location.reload(true);
                          $('.success').fadeIn(200).show();
                          $('.error').fadeOut(200).hide();
                         }
                    });

           return false;
        }

                                )});

        </script>

        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type = "text/javascript">
         $(document).ready(function(){
        $("a.deletebutton").click(function(){
             var del_id = $(this).attr("id");
             var info = 'id=' + del_id;
             var parent = $(this).parent();
            if(confirm("Sure you want to delete this game? !..There is no Undo")){
                $.ajax({
                    type: "get",
                    url: "delete.php?" + info,

                    context: document.body,
                    success: function(){

                        $('.p'+del_id).html('deleted');
                        $('.success').fadeIn(200).show();
                    }
                });
            }
             return false;
     });
 });
 </script>
     </body>
 </html>

add.php

<?php
    require('dbconfig.php'); //we cannot continue without this file, thats why using require instead of include

    if(isset($_POST['name']))
    {

    $name=addslashes($_POST['name']);
    $type=addslashes(($_POST['type']));
    $rating=addslashes($_POST['rating']);
    $release=addslashes($_POST['release']);
    $sql = 'INSERT INTO `games` (`Name`,`Type`,`Rating`,`Release Year`)  VALUES ("'.$name.'", "'.$type.'", "'.$rating.'", "'.$release.'")'; 
    mysql_query( $sql);
    if(!mysql_errno())
    echo " your game has been added to the list of games. ";
    }
?>
  • 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-05-26T18:09:52+00:00Added an answer on May 26, 2026 at 6:09 pm

    What your code is currently trying to do is the right principle: you are trying to trap the submit event on the form, make your Ajax request instead, and then cancel the default submit.

    The reason it doesn’t work is this line:

    $("add games").Submit(function(){ 
    

    “.submit()” should have a lowercase “s”, and the selector you are using, “add games”, is not going to return any elements because it looks for elements with the tag name “games” that are descendents of elements with tag name “add”.

    What you want to do is fix the case of the “s”, and select your element by id, which you do with “#yourid”. Your form name has the id “add”, so do this:

    $("#add").submit(function(){
    

    Also both your document.ready and your submit handler functions have an extra pair of {} curly braces around their bodies so you should delete those:

    $("#add").submit(function(){
       {                           // <- delete this {
          /*function body code*/
       }                           // <- delete this }
    });
    

    Also you are including the jquery.js script twice – once is enough. And you don’t need two document.ready handlers, you can combine them into a single one (though you can have more than one and that shouldn’t cause a problem).

    (There may be some other issues, but try this first and get back to us.)

    UPDATE: After the other fixes, I suspect the problem is now in your PHP, in the line:

    if(isset($_POST['Submit']))
    

    I don’t know PHP, but I assume this is checking for a request parameter called ‘Submit’ that you are not setting in your JS (it was the name of your submit button and would’ve been set for a “standard”, non-Ajax submit, but it won’t be included in your Ajax request). Try changing that line to use a request parameter that you are setting, like:

    if(isset($_POST['name']))
    

    Then, even if you don’t seem to get a response in the browser, check your database to see if records are being added.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am using php and mysql. i have a form to add record
I'm trying to add record locking to a site. This isn't database locking where
i am having dynamically created UITableView . I want to add 3 dummy row
I want to be able to add a record which acts like a symlink.
I want to add a record into access. The column name is Names: Now
I just created a new gem (using bundler) and want to add Active Record
I have a linked server, I want to add a record to the table
I want to add record index like MS Excel in my XamDataGrid control. I
i want to add something that record what the iphone is playing, i understand
I want to load form dynamically using following : HTML : <div id=add_new style=display:none>

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.