Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP, AJAX guestbook

Posted on 2009-03-30
2
3,282 Views
Last Modified: 2013-06-10
Hi, does anyone know from where I can start to build a PHP guestbook with AJAX effects?

I do know how to store data in a DB but never tried storing in an XML file.

Thanks.
0
Comment
Question by:Rassac
2 Comments
 
LVL 9

Accepted Solution

by:
Mahdii7 earned 500 total points
ID: 24023767
AJAX doesn't require storage in XML files, the "XML" just has to do with the request structure. You can store the guestbook values any way you like.

For simple AJAX commands, I suggest jQuery's AJAX library: http://www.jquery.com
You'll basically build the guestbook just as you normally would, but build a series of PHP files to send a request to. They will return information about the request. For example:
// The JS
function add_to_book(){
$.ajax({
 url:"objects/php_guestbook_requests.php",
 type: "POST",
 data: "name="+$("#name").val()+"&time=today",
 success: function(html){
  $("#the_div").html(html);
 }
});
}
 
// the HTML
<input name="name" type="text" /> (Name goes here)<br />
<div id="the_div"></div>
<button onclick="add_to_book()">Click to add</button>
 
// The PHP
 
if (isset($_POST['name'])){
 $add_to_db = your_db_add_function($_POST['name'], $_POST['time']);
 if ($add_to_db){
  echo "Great, welcome to our guestbook";
 }else{
  echo "error";
 }
}
 
// When a user puts a name in, and hits the button, the user is added to the book and "Great, welcome to our guestbook" is output to the div. All in AJAX.. Let me know if this doesn't make sense.

Open in new window

0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24026546
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wordpress Security 29 48
How to make a good PHP + MySQL + JS pagination system? 3 32
Cannot record Counter Strike with OBS 18.0.1 - too slow 1 46
S2D for SMB or vSAN 1 26
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Moving your enterprise fax infrastructure from in-house fax machines and servers to the cloud makes sense — from both an efficiency and productivity standpoint. But does migrating to a cloud fax solution mean you will no longer be able to send or re…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question