Advertisement

05.20.2008 at 01:45AM PDT, ID: 23416356
[x]
Attachment Details

Editing contents of a mysql database with php and jquery

Asked by synergiq in PHP Scripting Language, Asynchronous Javascript and XML (AJAX)

Tags:

I'm having a go at making a simple ajax script with PHP and jQuery. Basically it's a list that I want to be able to update without refreshing the page.

So far I can add new items to the list (which is working fine) but I want the query that gets the list to reload when you add a new item and I would also like to be able to delete and edit the items without refreshing the page aswell.

Can anybody show me or point me in the direction on how to do this?

So far I have this code (attached)

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
<?php
session_start();
$UserName = $_SESSION['UserName'];
include("action/restrict.php");
	//Connect to the database
	include("config/connect.php");
	//Include the functions file
	include("config/functions.php");
	//include settings file
	include("config/settings.php");
 
		$IDQuery = "select UserID from tbl_users where UserName = '$UserName'";
		$IDResult = mysql_query($IDQuery);
		$IDr = mysql_fetch_array($IDResult);
		$UserID = $IDr['UserID'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
	function add(){
		$.ajax({
			type: "POST",
			url: "action/add_item.php",
			data: 	"listtext=" + document.getElementById("listtext").value + 
					"&userid=" + document.getElementById("userid").value,
			success: function(html){
				$("#response").html(html);
			}
		});
		
		}
</script>
</head>
 
<body>
<div id="wrapper">
<div id="header">
<br/><a href="action/logout.php">Logout</a>
</div>
<div id="content">
<table class="listtable">
<?php
		
		$query = "SELECT * from tbl_list WHERE fld_UserID = '$UserID'";
		$result = mysql_query($query);
		$rownum = "0";
		
		while ($row = mysql_fetch_assoc($result)) {
		$rownum = $rownum+1;
		if ($rownum&1) {
			$rowclass = "row1";
		} else {
			$rowclass = "row2";
		}
		echo "<tr class=\"$rowclass\">";
		echo '<td>';
		echo "$rownum";
		echo '</td>';
		echo '<td>';
		echo '<img src="images/delete.png" class="listimage"/>';
		echo '</td>';
		echo '<td>';
		echo '<img src="images/edit.png" class="listimage"/>';
		echo '</td>';
		echo '<td>';
		echo $row['fld_listtext'];
		echo '</td>';
		echo '</tr>';
}
?>
</table>
 
<form action="" method="post">
<input type="text" name="listtext" id="listtext"/>
<input type="hidden" name="userid" id="userid"/>
<input type="button" name="submit" id="submit" value="Add" onclick="add()"/>
</form>
 
<div id="response"><!-- Our message will be echoed out here --></div>
</div>
</div>
</body>
</html>
[+][-]05.20.2008 at 02:18AM PDT, ID: 21604493

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:07AM PDT, ID: 21604679

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:14AM PDT, ID: 21604708

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:42AM PDT, ID: 21604829

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:53AM PDT, ID: 21604867

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 05:47AM PDT, ID: 21605598

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 11:10PM PDT, ID: 21612459

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 05:01AM PDT, ID: 21622916

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 05:34AM PDT, ID: 21623145

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 05:56AM PDT, ID: 21623329

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 12:12AM PDT, ID: 21629978

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, Asynchronous Javascript and XML (AJAX)
Tags: PHP / Ajax / jQuery / Javascript
Sign Up Now!
Solution Provided By: babuno5
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628