JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Computer Basics Hit List of Items to Talk About ● What and when to use left, right, middle, double and triple click? What and when to use left, right,
UNIT 12 LO4 BE ABLE TO CREATE WEBSITES Cambridge Technicals.
® IBM Software Group © 2006 IBM Corporation Additional AJAX Examples and Workshops This learning module provides additional AJAX use cases and examples.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Python and Web Programming
1 ONE TIME PRINT SETUP To print Requisitions from Banner, follow this process once: Open Microsoft Excel, select (1) TOOLS, then (2) MACROS, then (3) SECURITY.
Creating a Web Page HTML, FrontPage, Word, Composer.
JQuery CS 268. What is jQuery? From their web site:
1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
JavaScript & jQuery the missing manual Chapter 11
JQuery Page Slider. Our goal is to get to the functionality of the Panic Coda web site.Panic Coda web site.
INTRODUCTION TO DREAMWEAVER 8. What we already know…  Design basics  Contrast  Repetition  Alignment  Repetition  HTML.
Lou Stout Beaufort County Community College (252)
Server-side Scripting Powering the webs favourite services.
Adding Content To Your Faculty Page 1.Login 2.Create your Faculty Page 3.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
What is Museum Box? A Museum box is a way of presenting information that allows you to create a cube project that can be shared with others. You can use.
Bill's Amazing Content Rotator jQuery Content Rotator.
CARLSON SOFTWARE CONFERENCE DANIEL V. SYPERSMA VICTOR GRAPHICS.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
PHP meets MySQL.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
CAD3D Project. SketchUp - Project Create a new SketchUp project called InitialsXX where the XX are your first and last initial. Use the Rectangle tool.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Open the Goodyear Homepage Click on Teacher Tools.
Lesson 12: Working with Code-editing Features Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Go to your school’s web locker site school name.schoolweblockers.com) Your user name is the first letter of your first name, the first 4.
Basic & Advanced Reporting in TIMSNT ** Part Two **
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
Publishing Your Web Pages Ann Emmanuel SIUE Web Administrator
PHP Form Introduction Getting User Information Text Input.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
MGS 351 Introduction to Management Information Systems RECITATION 12.
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
JQuery Animation. If you look at example1.html, you will see that it is a basic web page with links to the jquery library, and a script.js file and some.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Perform a complete mail merge Lesson 14 By the end of this lesson you will be able to complete the following: Use the Mail Merge Wizard to perform a basic.
Intro to WordPress (Using XAMPP)
JavaScript and Ajax (Ajax Tutorial)
Data Virtualization Tutorial: Introduction to SQL Script
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Web Design and Development
PHP & MySQL Introduction.
Arrays and files BIS1523 – Lecture 15.
BASIC PHP and MYSQL Edward S. Flores.
How to Use Members Area of The Ninety-Nines Website
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
HTML Forms and User Input
Unit 27 - Web Server Scripting
Conditions and Ifs BIS1523 – Lecture 8.
In Class Programming BIS1523 – Lecture 11.
Presentation transcript:

jQuery MessageBoard

Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will combine it all: XHTML, CSS, PHP, jQuery, AJAX, and MySQL for a fully functioning web application. Lets set up the back end first. We will need a database to hold our messages. To set one up, go to MAMP and click on Open Start Page. When the start page opens, click on the PHPmyAdmin tab. If you are on XAMPP instead, click the admin button next to mysql on the control button to get to the same place.

Once you are in PHPmyAdmin, create a new database called messageboard.

Then make a table called messages with 3 fields. for the three fields we just need to create fields for the person's name, the message and a datetime field.

Next, put the mboardSTART folder in your htdocs directory and open the messageboard.php file in Dreamweaver. Currently the file contains just an HTML form. Nothing special. We will first build it just using PHP and MySQL to make sure the back end works, then we will build the front end with jQuery and AJAX technologies.

The first thing we are going to put in this file is the connection script to connect to the database. This is the simplest connection script we can have with PHP. We are not even bothering with any error checking. Go to the code pieces.txt file and copy this chunk of code and put it at the top of the html page on line one (above the tag).

The second piece of code goes at the bottom of the page, after all the HTML. This closes the connection to the database.

This function, written as it is, is rather dangerous, since there is no checking to see if the data entered is malicious at all. Essentially, you check to see if the send button on the form has been pressed. If it has, you take the data that came in the name and message fields and put them into local variables, then you create a query string that will add that data to the next record in the database, then you execute the query with the mysql_query function. Next we need a function that will output the messages that have been entered to the screen. Next, paste in the third piece of code, which is the form processor. It goes at the top of the page, directly after the first piece of code we put in. Probably on line 10.

Get the next piece of code and put it after the form processor function on the page. This function starts with a query that requests all the messages from the database, ordering them by datetime, descending, which will put the newest messages on top. Then we loop through the results, printing out a div tag, a p tag then the name of the person, then the message, then the closing p tag and the closing div tag. After that, we run the process_form() function and close the open php tag.

Put the fifth code piece, which is just one line under the form in the HTML. The get_messages() function must go where we want the messages to actually appear on the page. Under the form seems like a good spot. Ok, lets give this thing a whirl!

Ok, if you don't have any typos, it should be functional. Its not pretty, but you should be able to type into the name field and into the textarea and then submit the content to the database.

If you go back to phpMyAdmin and look at your database you should see records there. You can delete records from here if you want. You will notice that it is possible to add blank records by just clicking the submit button on our form. This is very bad, but we will actually control this with jQuery in a few minutes. Note this is not a full CRUD application, as we can not UPDATE or DELETE. Update would be weird on a message board, but you might think about ways of clearing out old messages.

Next we will create the front end. To do this we will add a bunch of files to our folder. First, duplicate the messageboard.php file twice and name the two copies display.php and process.php. We are going to split out the functions for displaying the records from creating the records. Also we will make use of the other files, including our jQuery.js file, the styles.css file, the script.js file for our own scripts and the index.html file.

On the process.php page, rip out everything except the connection to the database, the process_form() function and the close connection function. If you get confused, I have included the entire script on the code pieces page.

on the display.php page, rip out everything except the connection script, the get_message() function and the close connection script. Again, this is probably not the best coding practice, but we just want to do the minimum to get it to work right now. If you get confused, I included this entire script on the code pieces page.

The HTML file is essentially done. We don't have to do anything to it. I am just going to go through it here to explain everything on the page (which is not much). We have our links to the jQuery library and our own script file. Plus the link to our style sheet page.

The body of my page contains a div called container, a form for entering the posts, and an empty div called messages which will actually contain our messages. Notice the form has no action or method properties set. This is important as that will be handled by jQuery.

The form only has two fields, but there are some important things to note here. We are using labels, and I have one with a class of error, which will be used if someone tries to submit the form with no data at all. Notice my submit button has an ID too.

I set up some very basic styles on the styles.css page. You can add a lot to this later.

Now to make the magic happen. We will start with our document.ready function. Then we hide our error messages, so that when the page loads, we do not see them. Then we will add a click handler to our sent button. This is where we use the id we created for that button. When it is clicked, this anonymous function will run.

When we click the send button, we will first make sure all the error class labels are hiding again, incase any got turned on. Then we put the contents of the name field into a variable called name. Then we check to see if name is empty. If it is, we show the error label and stick the cursor back in that field. The return false is important because that is what will keep users from going on without filling out the field.

We do the same thing for the textarea field for the message. Be sure not to miss anything here if you copy and paste.

The next section, which is still in the click handler for the button, is where the magic happens. First, we create a dataString out of the contents of the two fields, then we use the $.ajax() function to send that data to the form. We want to send it by POST to the process.php file. The next line just clears out the message box so you could type something else in there if you want. Return false is important here because that is what will keep the form from actually trying to send using conventional methods.

At the end of the page, after the document.ready function, I create a new function called loadMessages() which will use the same trick we used before to load the display.php page into the messages div on the index.html page. The last thing I need is a way to trigger this function to happen. To do this, at the top of the script, at the beginning of the document.ready function, I add the setInterval() function which will make the loadMessages() function run every ten seconds.

Here is the whole script. Give her a whirl and see how it goes. If you typed everything correctly it should work. Congratulations on building a web app in a day. Now you can think of ways of improving it and building it out to a better user experience. There are tons of things that could be done.