473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Ajax-How to create delete button for each record after search

5
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record.


Filename : search_student.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("../user_access/user_access_control.php");
  3. include("../Database/database.php");
  4.  
  5. $searchStudentControl = new Access_user;
  6.  
  7. // call the levelAccess method to check the user access level
  8. $searchStudentControl->levelAccess($_SESSION['level'],1);
  9. ?>
  10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  11. <html>
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  14. <title>Untitled Document</title>
  15. <style type="text/css">
  16. <!--
  17. body {
  18.     margin-left: 0px;
  19.     margin-top: 0px;
  20.     margin-right: 0px;
  21.     margin-bottom: 0px;
  22. }
  23. .style1 {
  24.     font-size: 18px;
  25.     color: #FFFFFF;
  26. }
  27. -->
  28. </style>
  29. <script type="text/javascript" src="engine.js"></script>
  30. </head>
  31.  
  32. <body>
  33. <table width="707" border="0" cellspacing="0" cellpadding="0">
  34.   <tr>
  35.     <td width="62" height="31">&nbsp;</td>
  36.     <td colspan="5"></td><td width="1"></td>
  37.   </tr>
  38.   <tr>
  39.     <td>&nbsp;</td>
  40.     <td colspan="5"><form>
  41.       <table width="641" border="0" cellspacing="0" cellpadding="0">
  42.         <tr>
  43.           <td width="173"><input name="sData" type="text" id="sData">
  44.             by</td>
  45.           <td width="80"><select name="sSelect" id="sSelect">
  46.             <option value="Stu_ID">ID</option>
  47.             <option value="Stu_Name">Name</option>
  48.             <option value="Class_Code">Class</option>
  49.           </select></td>
  50.           <input name="sTable" type="hidden" value="student_recording">
  51.           <td width="72"><input name="search" type="button" onClick="getSearch(sData.value,sSelect.value,sTable.value,'search');" value="Search"></td>
  52.           <td width="316">&nbsp;</td>
  53.         </tr>
  54.       </table>
  55.     </form></td>
  56.   </tr>
  57.   <tr>
  58.     <td>&nbsp;</td>
  59.     <td colspan="3">&nbsp;</td>
  60.     <td width="6">&nbsp;</td>
  61.     <td width="207">&nbsp;</td>
  62.   </tr>
  63.   <tr>
  64.     <td>&nbsp;</td>
  65.     <td colspan="5" bgcolor="#999999">&nbsp;</td>
  66.   </tr>
  67.   <tr>
  68.     <td>&nbsp;</td>
  69.     <td colspan="5" bgcolor="#666699"><strong><span class="style1">:: Student Record :: </span></strong></td>
  70.   </tr>
  71.   <tr>
  72.     <td rowspan="4">&nbsp;</td>
  73.     <td colspan="5"></td>
  74.   </tr>
  75.   <tr>
  76.     <td width="230"><strong>Student Name </strong></td>
  77.     <td width="157"><strong>Contact Number </strong></td>
  78.     <td width="44"><strong>Class</strong></td>
  79.     <td>&nbsp;</td>
  80.     <td>&nbsp;</td>
  81.   </tr>
  82.   <tr>
  83.     <td colspan="5"><hr></td>
  84.   </tr>
  85.  
  86.   <tr>   
  87.     <td colspan="5">
  88.     <div id="getResult"></div>
  89.     </td>    
  90.   </tr>
  91. </table>
  92. </body>
  93. </html>
  94.  

Filename : engine.js
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2.  
  3. function deleteData(paction)
  4. xmlHttp=GetXmlHttpObject()
  5. if (xmlHttp==null)
  6.  {
  7.  alert ("Browser does not support HTTP Request")
  8.  return
  9.  } 
  10. var url="../user_access/process.php"
  11. url=url+"?id="+paction
  12. url=url+"&sid="+Math.random()
  13. xmlHttp.onreadystatechange=stateChanged 
  14. xmlHttp.open("GET",url,true)
  15. xmlHttp.send(null)
  16. }
  17.  
  18. function getSearch(pvalue,ptype,ptable,paction)
  19. xmlHttp=GetXmlHttpObject()
  20. if (xmlHttp==null)
  21.  {
  22.  alert ("Browser does not support HTTP Request")
  23.  return
  24.  } 
  25. var url="../user_access/process.php"
  26. url=url+"?value="+pvalue+"&type="+ptype+"&table="+ptable+"&action="+paction
  27. url=url+"&sid="+Math.random()
  28. xmlHttp.onreadystatechange=stateChanged 
  29. xmlHttp.open("GET",url,true)
  30. xmlHttp.send(null)
  31. }
  32.  
  33. function stateChanged() 
  34. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  35.  { 
  36.  document.getElementById("getResult").innerHTML=xmlHttp.responseText
  37.  } 
  38. }function GetXmlHttpObject()
  39. {
  40. var xmlHttp=null;
  41. try
  42.  {
  43.  // Firefox, Opera 8.0+, Safari
  44.  xmlHttp=new XMLHttpRequest();
  45.  }
  46. catch (e)
  47.  {
  48.  //Internet Explorer
  49.  try
  50.   {
  51.   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  52.   }
  53.  catch (e)
  54.   {
  55.   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  56.   }
  57.  }
  58. return xmlHttp;
  59. }
  60.  

Filename : process.php
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Untitled Document</title>
  6. <style type="text/css">
  7. <!--
  8. body {
  9.     margin-left: 0px;
  10.     margin-top: 0px;
  11.     margin-right: 0px;
  12.     margin-bottom: 0px;
  13. }
  14. .style1 {
  15.     font-size: 18px;
  16.     color: #FFFFFF;
  17. }
  18. -->
  19. </style>
  20. <script type="text/javascript" src="../admin_sys/engine.js"></script>
  21. </head>
  22. <?php
  23. include("../Database/database.php");
  24.  
  25.     if($_GET['action'] == "search"){
  26.       showData(); 
  27.     }else if($_REQUEST['action'] == "Edit"){
  28.         edit();
  29.     }else if($_REQUEST['action'] == "delete"){
  30.         delete();
  31.     }
  32.     function view(){
  33.         global $conn;
  34.  
  35.         $Viewsql = "SELECT * FROM " . $_REQUEST['Table'] . " WHERE ( " . $_REQUEST['Type'] . "='" . $_REQUEST['sID'] . "')";
  36.         $result = $conn->query($Viewsql);    
  37.  
  38.         while($data = $result->fetch_assoc()){
  39.                  echo $data['Stu_ID'];
  40.                 echo "<br>";
  41.                 echo $data['Stu_Name'];
  42.                 echo "<br>";
  43.                 echo $data['Stu_Race'];                
  44.         }
  45.     }
  46.  
  47.     function edit(){
  48.     }
  49.  
  50.     function delete(){
  51.         global $conn;
  52.  
  53.         $sql="DELETE FROM ".$_GET['table']." WHERE (Stu_ID = ".$_GET['id'].")";
  54.         $conn->query($sql);
  55.         echo "Data Deleted";
  56.         showData();
  57.     }
  58.  
  59.     function showData(){
  60.  
  61.         global $conn;
  62.  
  63.         $sql="SELECT * FROM ".$_GET['table']." WHERE (".$_GET['type']." ='".$_GET['value']."')";
  64.         $result = $conn->query($sql);
  65.  
  66.         echo "<table width='641' border='0' cellspacing='0' cellpadding='0'>";
  67.         while($data = $result->fetch_assoc()){
  68.         echo "<tr>";
  69.         echo "<td width='230'>" . $data['Stu_Name'] . "</td>";
  70.         echo "<td width='153'>" . $data['Stu_Tel'] . "</td>";
  71.         echo "<td width='22'>" . $data['Class_Code'] . "</td>";
  72.         echo "<td width='48'></td>";
  73.         echo "<td width='188'><div align='right'>";
  74.         echo "<input type='button' onClick='process('delete');' value='Delete'>";
  75.         echo "</div></td>";
  76.         echo "</tr>";
  77.         echo "<tr>";
  78.         echo "<td colspan='5'><hr></td>";
  79.         echo "</tr>";
  80.           }
  81.       echo  "</table>";
  82.      }
  83. ?>
  84.  
Im getting error if i put input type='button' onClick='process('delete');' value='Delete'>"; in process.php. I know my design structure is not correct. Can anyone get me an idea about the correct way to design.

can i display the delete button for each record when the record is exist in search_student.php.

Thanks in advance
Bluez
Apr 15 '07 #1
3 3404
acoder
16,027 Expert Mod 8TB
The reason why you're getting an error is that you've got a quote within a quote. Javascript thinks the quote has ended and then comes across the word 'delete' which it obviously doesn't understand.

You have two options: either escape the quotes using backslash (\) or use single and double quotes together, e.g.
[HTML]<input type='button' onClick="process('delete');" value='Delete'>[/HTML]
Apr 16 '07 #2
bluez
5
Thx..it's work

and sorry for the late reply
Apr 21 '07 #3
acoder
16,027 Expert Mod 8TB
Thx..it's work

and sorry for the late reply
No problem. Glad you got it working.
Apr 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: darrel | last post by:
Anyone using Ajax with .net? Are there any controls/tools that make building with ajax easier or is it, for now, just a matter of connecting the javascript to the back end manually as needed? ...
2
by: Alex | last post by:
Example uploaded to: http://www.clickatus.com/ajax/ BTW - This is for FIREFOX, won't work in IE. I don't know why but when it is executed the browser still in loading state... Even though...
3
by: caston | last post by:
Well, everybody can now agree with the fact that the Ajax hype is over. Still multiple Ajax Frameworks are flourishing, aren't they? So, last night I questioned myself with the following: "When...
0
by: Free Ebooks | last post by:
81 AJAX and 24 JavaScript Ebooks Here are some of the AJAX topics and areas covered by these ebooks: Rails and AJAX Building Ajax Web Applications Creating Ajax Web Pages Ajax Patterns Ajax...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
8
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm about to finally make the jump and start a new site using AJAX. THe question i have for all of you AJAX developers out there is which one? 1. The Standard AJAX frame work 2. The Tool kit....
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I am just stating to use ajax, and have a perfect place to use the accordion control. I have it working fine, but need to have a normal asp button in one of the panes that fires an onclick event...
7
by: Joe | last post by:
I added some ajax to my asp.net web site and will Ajax just doesn't seem to work. Does Any one PLEASE have any ideas on why Ajax doesn't work on Apache 2.2.6 w/asp.net 2.0
29
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to...
6
by: Scott M. | last post by:
What is the version number of AJAX when we talk about ASP .NET AJAX in VS 2008?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.