473,769 Members | 3,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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='proces s('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 3426
acoder
16,027 Recognized Expert Moderator MVP
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="proces s('delete');" value='Delete'>[/HTML]
Apr 16 '07 #2
bluez
5 New Member
Thx..it's work

and sorry for the late reply
Apr 21 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
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
1213
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? -Darrel
2
1860
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 XMLHttpRequest already got its string from the server... Any help?
3
1780
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 Ajax Frameworks will be gone? What is required to get rid of them and start using browsers?" (To be more precise, I should probably also mention what kind of frameworks do i mean. These are: Dojo, BackBase, Qooxdoo etc.) I've got an answer that I...
0
2350
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 Tutorial Ajax Best Practices Ajax XMLHttpRequest and Struts
2
4281
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 functioning as desired when I test it on my machine using Visual Studio 2005. From what I have determined, the files I am forgetting are the JavaScript files from the Microsoft AJAX Library (See "To install Microsoft AJAX Library" at the bottom of...
8
1710
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. 3. Or are there others out there. 4. Should i not do AJAX at all because it still posts back the entire page even though only the section is refreshed. (someone tell me i'm wrong here and why please!)
4
6280
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 as normal. The button works fine outside of the pane, but once I put it in the pane it no longer fires the event. How can I get a button in the accordion to run a function on the server on the onclick event? Thanks.
7
2097
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
3324
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 use it in sync mode. Any ideas what can I do? Thanks, Zalek.
6
1611
by: Scott M. | last post by:
What is the version number of AJAX when we talk about ASP .NET AJAX in VS 2008?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.