Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add and delete with ajax or jquery
    primarykey
    data
    text
    <p>I am very new to ajax and jquery but I know some php. I have got a page where i get students detail. All i want is when i click add button that student will be inserted into paid table and that students name will show up on the page. There will be a delete button next to student`s name and it should delete the student if i click on it. </p> <blockquote> <p>will it be hard to do this? Do you know any samples on internet?</p> </blockquote> <p>How should my ajax code be according to my pages?</p> <blockquote> <p>this is my student page</p> </blockquote> <pre><code>&lt;? include ("connect.php"); $id = trim($_GET['id']); $result = mysql_query("SELECT * FROM students WHERE students_id='$id'"); while($row = mysql_fetch_array($result)) { $studentname = $row['students_name']; } ?&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" name="form"&gt; &lt;input type="hidden" id="studentname" name="studentname" value="&lt;? echo $studentname; ?&gt;" /&gt; &lt;input type="submit" id="addme" name="addme" value="Add &lt;? echo $studentname; ?&gt;" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <blockquote> <p>this is my add page</p> </blockquote> <pre><code>&lt;? include ("connect.php"); if (isset($_POST['addme'])) { $studentname = $_POST["studentname"]; mysql_query("INSERT INTO paid SET paid_name = '$studentname'"); mysql_close($con); } ?&gt; </code></pre> <blockquote> <p>This is my delete page</p> </blockquote> <pre><code>&lt;? include ("connect.php"); $delete = $_POST["delete"]; mysql_query("DELETE FROM paid WHERE paid_id='$delete'"); mysql_close($con); ?&gt; </code></pre> <blockquote> <p>This is my show page:</p> </blockquote> <pre><code>&lt;? include ("connect.php"); $result = mysql_query("SELECT * FROM paid"); while($row = mysql_fetch_array($result)) { echo $row['paid_name']; echo "&lt;br&gt;"; } mysql_close($con); ?&gt; </code></pre> <blockquote> <p>This is my database:</p> </blockquote> <pre><code>-- -- Table structure for table `students` -- CREATE TABLE IF NOT EXISTS `students` ( `students_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `students_name` varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (`students_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; -- -- Dumping data for table `students` -- INSERT INTO `students` VALUES (1, 'David'); INSERT INTO `students` VALUES (2, 'Lisa'); INSERT INTO `students` VALUES (3, 'Jack'); INSERT INTO `students` VALUES (4, 'Michelle'); CREATE TABLE IF NOT EXISTS `paid` ( `paid_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `paid_name` varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (`paid_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; -- -- Dumping data for table `paid` -- INSERT INTO `paid` VALUES (1, 'Michelle'); INSERT INTO `paid` VALUES (2, 'Lisa'); </code></pre> UPDATED#### Added my pages.
    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