This series of the videos explains how to create Photo Gallery using PHP, MySQL, ImageMagic and jQuery. Using PHP you will be able to add, modify and populate data stored on the MySQL Database and display records of all images on the page. ImageMagic will help us to resize and crop images to the relevant dimentions, while jQuery will provide the support in the presentation of the gallery. The last two chapters are dedicated to adding the earlier created gallery to our Content Management System. Over 4 hours of videos!!!

Dreamweaver tutorials

 
  • Link Exchange System with Dreamweaver CS3
  • Add Link Page

In this part of the tutorial I will be explaining you how to create Add link page.

Open links_add.php file located in the admin folder of your site's root.
Press Ctrl+A and hit Delete button to remove the entire content of the page.
Go to Modify > Templates > Apply Template to Page.
In the new window choose admin_temp and click Select to apply template to the page (Fig. 129).

Apply web template using Dreamweaver CS3
Fig. 129

Save file and in the Code view remove <p>Content Placeholder</p>.
Open Application panel and in the Server Behaviors tab press + button.
From the list of options choose Recordset (Fig. 130).

Application panel in Dreamweaver CS3
Fig. 130

In the new window type the following:
Name rsCategories
Connection conndb
Table tbl_categories
Columns All
Filter None
Sort catname > Ascending
(Fig. 131)

Create recordset using Dreamweaver CS3
Fig. 131

Click OK and save the file.
Identify the line which says <p id="ptitle">Title Placeholder</p> and replace Title Placeholder with Add link.
Now place cursor at the end of this paragraph and press Enter to create a new line. Leave your cursor at the begining of the newly created line and change the view to Design.
Now from the Data tab of the Insert panel choose Record Insertion Form Wizard (Fig. 132).

Create recordset using Dreamweaver CS3
Fig. 132

In the Record Insertion Form window choose:
Connection conndb
Table tbl_links
After insertin, go to links_added.php

In Form fields section do the same as in previous section - remove linkid and linkdate by selecting them from the list and pressing - button at the top.
Rename and rearange the order of the remaining fields by changing their labels and order to be as follow:
linkemail Email:
linkcat Category:
linktitle Link title:
linkurl URL:
linkrecip Reciprocal:
linkdescr Description
linkapproved Approved?:

Now go back to linkcat and from the Display as choose Menu and click Menu Properties button.
In the Menu Properties window choose the following:
Populate menu items From database
Recordset rsCategories
Get labels from catname
Get values from catid

Click OK (Fig. 133).

Record Form Insertion Wizard using Dreamweaver CS3
Fig. 133

Select linkdescr and from the Display as menu choose Text area.
Lastly select linkapproved and again, from the Display as menu choose Menu.
This time choose:
Populate menu items Manually
and in the Menu items create two options:
Label Yes
Value y
click + button and add another:
Label No
Value n
(Fig. 134)

Create select menu using Dreamweaver CS3
Fig. 134

Click OK and OK again (Fig. 135).

Record Form Insertion Wizard using Dreamweaver CS3
Fig. 135

This will insert Insert Record form into our page (Fig. 136).

Insert record form in Dreamweaver CS3
Fig. 136

Place your cursor anywhere inside of the table and select <table> tag selector
(Fig. 137).

Insert record form in Dreamweaver CS3
Fig. 137

From the Properties panel choose:
Table Id tblinsert
CellPad 0
CellSpace 0
Border 0
Align Default
(Fig. 138)

Properties panel in Dreamweaver CS3
Fig. 138

Now select button and press Ctrl+T. At the end of the Edit tag type id="button" and press Enter (Fig. 139).

Edit tag in Dreamweaver CS3
Fig. 139

Place your cursor in the first cell of the first column (Email:) and press Ctrl+T on your keyboard twice. Replace td nowrap="nowrap" align="right" (Fig. 140) with th
(Fig. 141) and press Enter.

Edit table cell tag in Dreamweaver CS3
Fig. 140

Replace td tag with th in Dreamweaver CS3
Fig. 141

Do the same will the remaining cells in the first column.
Your page in Dreamweaver's Design view should now look like in Fig. 142.

Design view in Dreamweaver CS3
Fig. 142

Switch to the Code view. Identify the line which says:

<th>Email:</th>
<td><input type="text" name="linkemail" value="" size="32" /></td>

After name="linkemail" type id="linkemail".
Go to <th>Email:</th> and place your cursor before the word Email:.
Type <label for="linkemail">.
Now move your cursor after the word Email: and type </label>.
All together should now look like this:

<th><label for="linkemail">Email:</label></th>
<td><input type="text" name="linkemail" id="linkemail" value="" size="32" /></td>

Do the same with all remaining <th> tags and their input, select and textarea form fields using their relative name's for id and for attributes.

Identify the line which says:

<table border="0" cellpadding="0" cellspacing="0" id="tblinsert">

Place you cursor at the end of this line, press Enter to create a new line and type:

<caption>Add new link</caption>

Also, before moving on, change the id="form1" in the <form> tag to id="forminsert"

Now, once all this is done, bofore we start adding modifications to the code we will add one of the Server Behaviors which checks if the record already exists in the database before adding it.
This behaviour has been created specifically for checking Username in the user registration forms but it will work very well for this purpose as well.

To apply this behaviour switch to Design view, go to the Server Behaviors tab of the Application panel and click + sign. From the list of options choose:
User Authentication > Check New Username (Fig. 143).

Check new username server behavior
Fig. 143

In the Check New Username window choose linkurl for Username field and links_already_exists.php for If already exists, go to (Fig. 144). Click OK and save the file.

Applying server behavior
Fig. 144

Ok - now all we've got left is to apply sticky form fields and validation and our page is done.
First we are going to apply server side validation - same one as in the previous chapter.
Identify the line which reads:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

Create a new line and copy and paste the following validation code:

if (!empty($_POST['linkemail'])) {

if ($_POST['linkcat'] == "" || $_POST['linktitle'] == "" || $_POST['linkurl'] == "" || $_POST['linkdescr'] == "") {

if ($_POST['linkcat'] == "") {
$mess = "<p>Please choose category</p>";
}
if ($_POST['linktitle'] == "") {
$mess .= "<p>Please provide link title</p>";
}
if ($_POST['linkurl'] == "") {
$mess .= "<p>Please provide link URL</p>";
}
if ($_POST['linkdescr'] == "") {
$mess .= "<p>Please provide description.</p>";
}

} else {

Now identify the line which says:

header(sprintf("Location: %s", $insertGoTo));
}

and add an extra closing curly bracket } at the end so that it reads:

header(sprintf("Location: %s", $insertGoTo));
}}

Now before we move on I would like to stop for a while and explain you what actually has happened here.

The line which reads:

if (!empty($_POST['linkemail'])) {

checks if the field linkemail is not empty. Yes, we are NOT applying validation to this field if it's empty because sometimes may happen that you will not have an email address of the website which you are adding link to, therefore if we make email field mandatory you would always have to enter email address, otherwise you wouldn't be able to add new record. I hope that makes sense.
Email address is only validated if there is a data to validate. In fact we are only validating linkcat, linktitle, linkurl and linkdescr which are mandatory fields by checking if they are returning an empty string (""):

if ($_POST['linkcat'] == "" || $_POST['linktitle'] == "" || $_POST['linkurl'] == "" || $_POST['linkdescr'] == "")

If any of them returns an empty string then the new variable is created called $mess.
This variable - if exists - will display a message, which tells us which fields need to be filled in before the form will be successfully submitted.

That's it - quite simple if conditional statement. If you want to learn more about different statements used in PHP try to google it - there's a lot of good resources available out there.

Anyway, let's move on. Identify line which says:

<caption>Add new link</caption>

Create a new line after it and type the following:

<?php if(isset($mess)) { ?>
<tr>
<td colspan="2" class="messagebox"><?php echo $mess; ?></td>
</tr>
<?php } ?>

Our validation is completed. You can test it now by pressing F12 on your keyboard.

The last step will be to apply sticky form fields to our form. Again, we will be using if statement to find out if there is a value assigned to the form field. If the answer is yes than we will display this value in its field, otherwise field will remain empty.

Identify the line which reads:

<input type="text" name="linkemail" id="linkemail" value="" size="32" />

Inside of the value attribute type the following statement:

<?php if (isset($_POST['linkemail'])) { echo $_POST['linkemail']; } ?>

Now the whole input field should look like this:

<input type="text" name="linkemail" id="linkemail" value="<?php if (isset($_POST['linkemail'])) { echo $_POST['linkemail']; } ?>" size="32" />

Now identify the line which reads:

<select name="linkcat" id="linkcat">

Place your cursor at the end of this line and create a new line by pressing Enter on your keyboard.
Now type:

<option value=""
<?php
$OK = isset($_POST['linkcat']) ? true : false;
if ($OK && $_POST['linkcat'] == "") { ?>
selected="selected"
<?php } ?>
>...Choose category...</option>

Now, three lines down you should see the line which reads:

<option value="<?php echo $row_rsCategories['catid']?>" ><?php echo $row_rsCategories['catname']?></option>

We need to slightly modify the <option> tag so it reads:

<option value="<?php echo $row_rsCategories['catid']; ?>" <?php if ($OK && $_POST['linkcat'] == $row_rsCategories['catid']) { ?> selected="selected" <?php } ?> >

Identify the line which reads:

<input type="text" name="linktitle" id="linktitle" value="" size="32" />

For the value of this input field type:

<?php if (isset($_POST['linktitle'])) { echo $_POST['linktitle']; } ?>

For the line which reads:

<input type="text" name="linkurl" id="linkurl" value="" size="32" />

assign the value of:

<?php if (isset($_POST['linkurl'])) { echo $_POST['linkurl']; } ?>

For the line:

<input type="text" name="linkrecip" id="linkrecip" value="" size="32" />

assign the value of:

<?php if (isset($_POST['linkrecip'])) { echo $_POST['linkrecip']; } ?>

For textarea field type which reads:

<textarea name="linkdescr" id="linkdescr"></textarea>

in between the <textarea></textarea> tags type:

<?php if (isset($_POST['linkdescr'])) { echo $_POST['linkdescr']; } ?>

Because textarea hasn't got a value attribute we need to provide a closing tag and place the value of it in between an opening and closing tag.

This line shoud now look like this:

<textarea name="linkdescr" id="linkdescr"><?php if (isset($_POST['linkdescr'])) { echo $_POST['linkdescr']; } ?></textarea>

Now identify the line which reads:

<option value="y" <?php if (!(strcmp("y", ""))) {echo "SELECTED";} ?>>Yes</option>

Replace an existing php statement which reads:

<?php if (!(strcmp("y", ""))) {echo "SELECTED";} ?>

with the following one:

<?php if (isset($_POST['linkapproved']) && $_POST['linkapproved'] == "y") { ?>selected="selected"<?php } ?>

Do the same with the next line except this time replace the PHP content with the following:

<?php if (isset($_POST['linkapproved']) && $_POST['linkapproved'] == "n") { ?>selected="selected"<?php } ?>

We have just completed sticky form fields and we are actually finished with this page. The only last thing you may want do is to add * symbol to the mandatory fields so that administrator knows which fields are required (Fig. 145).

Mandatory fields
Fig. 145

Open links_already_exists.php page, apply template to it, change the <p id="ptitle">Title Placeholder</p> to <p id="ptitle">Duplicate record</p> and create a new line after this.
On new line type:

<p>This URL already exists in our database.<br />
Please <a href="javascript:history.go(-1)" id="addlink">go back and try again</a>.</p>

Identify the line which says:

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

Create a new line after <!-- InstanceBeginEditable name="head" --> and type:

<script type="text/javascript">

onload=
function getFocus()
{
var toFocus = document.getElementById("addlink");
toFocus.focus();
}

</script>

Now open links_added.php and apply template to it.
In Code view replace <p id="ptitle">Title Placeholder</p> with <p id="ptitle">Link added</p> and create a new line after this.
On new line type:

<p>Your link has been addess successfully.<br />
<a href="links_add.php" id="addlink">Add another link</a>.</p>

Again, create a new line after <!-- InstanceBeginEditable name="head" --> and type:

<script type="text/javascript">

onload=
function getFocus()
{
var toFocus = document.getElementById("addlink");
toFocus.focus();
}

</script>

This way we have completed this section and can move to the next one in which I will be explaining how to create Add category page

<< Edit Link Page | Add Category Page >>

 
  • Thank you for subscribing to our newsletter.
  • To complete registration please click on the link in the email which has been sent to you.
  • Invalid first name
  • Invalid last name
  • Invalid email address

Website Design Company | Website Design Company Sussex | Website Design Company Chichester | Website Design Packages | Tutorials Resources | Articles | Contact
© Web Design Tutorials – Sebastian Sulinski