Note that there are some explanatory texts on larger screens.

plurals
  1. PODeletion and insertion of new records to DB without refreshing
    primarykey
    data
    text
    <p>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.</p> <p>i have 5 columns from my database and the ID is hidden with auto increment. </p> <p>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???</p> <p>this is my main file with the calls to delete and add games. </p> <pre><code> &lt;script type = "text/javaScript" src ="http://code.jquery.com/jquery- latest.js""&gt;&lt;/script&gt; &lt;script type = "text/javascript"&gt; $(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 + '&amp;username=' + type + '&amp;password=' + rating + '&amp;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; }); }); &lt;/script&gt; &lt;body&gt; &lt;?php include("dbconfig.php"); $sql = "SELECT * FROM games"; $result = mysql_query($sql); while ($record = mysql_fetch_array($result)){ echo "&lt;/br&gt; Game ID: " .$record['ID']. "&lt;/br&gt; Game Name: " .$record['Name']. "&lt;br /&gt; Game Type: ".$record['Type']. "&lt;br /&gt; Rating: ".$record['Rating']."&lt;br /&gt; Year Released: ".$record['Release Year']."&lt;br /&gt; &lt;br /&gt;" ?&gt; &lt;a href="#" id="&lt;?php echo $record["ID"]; ?&gt;" class="deletebutton"&gt;&lt;img src="trash.png" alt="delete"/&gt;&lt;/a&gt; &lt;?php } ?&gt; &lt;form name="add" id ="add" action="add.php" method="post"&gt; &lt;input class ="gameID" type="hidden" id="ID" value = " ' .$record['ID'] . ' " /&gt; &lt;b&gt;Game Name: &lt;/b&gt; &lt;input type="text" id="name" size=70&gt; &lt;b&gt;Game Type:&lt;/b&gt; &lt;input type="text" id="type" size=40&gt; &lt;b&gt;Rating: &lt;/b&gt; &lt;input type="number" id="score" min="1.0" max="10.0" step ="0.1"/&gt; &lt;b&gt;Year Released: &lt;/b&gt; &lt;input type="number" min="1900" max="2011" id="Yreleased" value="1985" size=4&gt; &lt;p&gt;&lt;input type="submit" name="Submit" id = "Submit" value="Add Game" class = "add games"&gt;&lt;/p&gt; &lt;/form&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;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; }); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>and i have very simple php files for add, for delete and for the dbconfig </p> <p>for delete.php</p> <pre><code>&lt;?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); } ?&gt; </code></pre> <p>and this is my add.php and my dbconfig.php in the end</p> <pre><code>&lt;?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. "; ?&gt; </code></pre> <p>and last my dbconfig</p> <pre><code> &lt;?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); ?&gt; </code></pre> <p>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.</p>
    singulars
    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