13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Adding Ajax Elements to Earlier Projects<br />

877<br />

<br />

Although you may or may not need all the items in these files in the Ajax-enabled version<br />

of the bookmark addition sequence, the comment at the beginning says it all—<br />

every file will contain all our functions <strong>and</strong> exceptions. In this situation, as<br />

you are moving from a series of dynamic pages to all-in-one Ajax-enabled functionality,<br />

it is better to have a few extra elements than to remove core functionality before you are<br />

sure you don’t need it. Keep the first line of add_bms.php as is.<br />

The second line, which begins or continues a user session, should also remain as is;<br />

even in the Ajax-enabled version of this action you will want some sense of security<br />

intact. Similarly, the third line can remain as well.This line gives the shortname<br />

$new_url to the POST value sent through the request:<br />

$new_url = $_POST['new_url'];<br />

Finally, you are at the point in which you can remove something, namely this line:<br />

do_html_header('Adding bookmarks');<br />

Because you are already on a page (add_bm_form.php) that contains HTML header<br />

information, there is no need to repeat it again—you’re not moving to a different page.<br />

This repetition produces the two sets of header graphics <strong>and</strong> titles that you see in Figure<br />

34.4. For similar reasons, you can eliminate two lines at the end of add_bms.php as well:<br />

display_user_menu();<br />

do_html_footer();<br />

If you remove these elements, upload the file to the server, <strong>and</strong> attempt to add another<br />

bookmark, the results will be closer to what you expect, although there are still some<br />

changes to be made. Figure 34.5 shows the application display with changes made in<br />

the code to this point.<br />

We still have a duplicate message regarding the status of the user as “logged in,” but<br />

the issues are not nearly as unappealing as before.The next step is to remove the duplicate<br />

messages <strong>and</strong> to change some of the other exceptions-related functionality so that it<br />

makes sense in an Ajax-environment.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!