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 6802489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:13:46+00:00 2026-05-26T19:13:46+00:00

i am trying to add and delete records(games) from my database using jquery and

  • 0

i am trying to add and delete records(games) from my database using jquery and ajax.
i am still a junior software engineer and learning the basics of web development but i have this task to accomplish and unsure what i am missing for it to work.

i have 5 columns from my database and the ID is hidden with auto increment.

my question is what is broken in the code that is not letting me add or delete a game and reflect it on the database???

this is my main file with the calls to delete and add games.

            <script type = "text/javaScript" src ="http://code.jquery.com/jquery-             latest.js""></script>
         <script type = "text/javascript">
          $(document).ready(function(){
          $("add games").Submit(function()
          $("#add").load("add.php");  {
         var id = $("#ID").val();
         var name = $("#name").val();
         var type = $("#type").val();
         var rating = $("#score").val();
         var release = $("Yreleased").val();
         var dataString = 'ID=' + id 'name='+ name + '&username=' + type + '&password=' + rating +                           '&gender=' + release;
         if (id =='' || 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(){
         $('.success').fadeIn(200).show();
         $('.error').fadeOut(200).hide();
         }
         });
         }
         return false;
         });
         });



         </script>


         <body>
         <?php

         include("dbconfig.php");
         $sql = "SELECT * FROM games";
         $result = mysql_query($sql);
         while ($record = mysql_fetch_array($result)){

         echo "</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> 






  <?php
         }

         ?>

         <form name="add" id ="add" action="add.php"  method="post">
         <input class ="gameID" type="hidden" id="ID" value = " ' .$record['ID'] . ' " /> 
         <b>Game Name: </b> <input type="text" id="name" size=70> 
         <b>Game Type:</b> <input type="text" id="type" size=40>
         <b>Rating: </b> <input type="number"  id="score" min="1.0" max="10.0"  step ="0.1"/>
         <b>Year Released: </b> <input type="number"  min="1900" max="2011" id="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() {

         $("a.deletebutton").click(function(){

         var del_id = element.attr("id");
         var info = 'id=' + del_id;
         var parent = $(this).parent();
         if(confirm("Sure you want to delete this game? !"))
         {
         $.ajax({
         type: "get",
         url: "delete.php",
         data: parent.attr('id').replace('record-',"),
         success: function(){
         }
         });
         $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
         .animate({ opacity: "hide" }, "slow");
         }
             return false;
             });
             });
             </script>




             </body>

and i have very simple php files for add, for delete and for the dbconfig

for delete.php

<?php

// This is a sample code in case you wish to check the username from a mysql db table
include("dbconfig.php");
if(($_GET['id'])
{
$id=$_GET['id'];

 $sql = "DELETE from games where ID='.(int)$_GET['id'];
 $result= mysql_query( $sql);






}

?>

and this is my add.php and my dbconfig.php in the end

<?php
include("dbconfig.php");

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

$name=$_POST['name'];
$type=$_POST['type'];
$rating=$_POST['score'];
$release=$_POST['Yreleased'];
$sql = ("INSERT INTO games  VALUES ($name, $type, $rating, $release)");

echo " your game has been added to the list of games. ";
?>

and last my dbconfig

 <?php
$user_name = "root";
$password = "";
$database = "gamebook";
$server = "localhost";


$bd = mysql_connect($server, $user_name, $password) or die ('I cannot connect to the        database because:' . mysql_error());
mysql_select_db($database);
?>

this is the first time every i post a question and ask, so if i did something unacceptable or that should have been done otherwise, i would appreciate the tips, help, links, or if someone can help me on how to fix my issue.
i can read from the database, but not add or delete from it dynamically.

  • 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-26T19:13:46+00:00Added an answer on May 26, 2026 at 7:13 pm

    delete.php

    <?php
      require('dbconfig.php'); //we cannot continue without this file, thats why using require instead of include
      if(isset($_GET['id'])){
        $id=(int)$_GET['id'];
        $sql = 'DELETE FROM `games` WHERE `ID`="'.$id.'" LIMIT 1';
        mysql_query( $sql);
        echo 'deleted';
      }
    ?>
    

    add.php

    <?php
      require('dbconfig.php'); //we cannot continue without this file, thats why using require instead of include
    
        if(isset($_POST['Submit'])){
    
        $name=addslashes($_POST['name']);
        $type=addslashes($_POST['type']);
        $rating=addslashes($_POST['score']);
        $release=addslashes($_POST['Yreleased']);
        $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. ";
        }
    ?>
    

    index.php take from here: http://pastebin.com/NVbheAJZ

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

Sidebar

Related Questions

I'm trying add a tab to my web page that looks like this: Using
Im trying to add an element to a database and then return a new
Im trying to add a Jquery validation script to a form plugin for wordpress.
I am running into a problem trying to use AJAX and jQuery with ASP.NET
I am facing a problem where I am trying to add data from a
I'm trying to add many series to a chart using VBA, as in the
Using telerik mvc grid with ajax, give me some headaches. I am trying to
I'm trying to delete a record in mysql using php. What do I have
I'm trying to use Entity Framework 4.0 to add and remove records with a
I am trying to make a nested model form in which I can add/delete

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.