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
  • Submit link page

This, last chapter of the entire tutorial will explain how to create a page where visitors can submit their link for approval.

Open links_submit.php and in Code view identify the line which reads:

<?php include ('../includes/search_engine.php'); ?>

Place your cursor at the end of this line and hit Enter on your keyboard to create a new line. On new line type:

<p id="title">Submit URL</p>

Hit Enter again to create another new line.
Change view to Design, go to the Bindings section of the Application panel, click + sign and choose Recordset (Query) (Fig. 219).

Create Recordset, query in Bindings panel image
Fig. 219

In the Recordset window press Simple button ­ this is if you are in the Advanced view (Fig. 220).

Recordset advanced window image
Fig. 220

In the simple view choose the following:

Name: rsCategories
Connection: conndb
Table: tbl_categories
Columns: All
Filter: None
Sort: catname > Ascending
(Fig. 221)

Creating recordset image
Fig. 221

Click OK and Save the file.

Go to the Code view and make sure your cursor is placed on the new line after the line which reads:

<p id="title">Submit URL</p>

Change view back to Design and from the Data tab of the Insert panel choose Record Insertion Form Wizard (Fig. 222).

Record insertion form wizard image
Fig. 222

In the Record Insertion Form window choose the following:

Connection: conndb
Table: tbl_links
After inserting, go to: links_submitted.php

In the Form fields section remove linkid, linkdate and linkapproved by selecting each one and clicking ­ sign.

Now specify the order in which fields will be displayed by selecting each one and rearranging using the arrows in the right-top corner so that they are as follow:

linkemail
linkcat
linktitle
linkurl
linkrecip
linkdescr

Once they are in order, we can now rename the labels for them and selecting the relevant form field type by selecting each element and changing its Label and Display as values.
Each one should have the following values:

linkemail - *Email: > Text field
linkcat - *Category: > from the Display as choose Menu and click Menu Properties button (Fig. 223).

Creating recordset image
Fig. 223

In the Menu Properties window select From database radio button and choose the following:

Recordset: rsCategories
Get labels from: catname
Get values from: catid

Click OK and continue with the remaining fields(Fig. 224).

Creating menu from database image
Fig. 224

linktitle ­ *Link title: > Text field
linkurl - *URL: > Text field
linkrecip - *Reciprocal link: > Text field
linkdescr - *Description: > Text area

The Record Insertion Form window should now look like in Fig. 225.

Record Insertion Form window image
Fig. 225

Click OK to add the form to our page and Save the file.

Place your cursor anywhere within the table and press <table> tag on the status bar to select the entire table (Fig. 226).

Select table image
Fig. 226

In the Properties panel from the Table Id dropdown menu choose tblsubmit, from the Align dropdown menu choose Default and for the CellPad, CellSpace and Border type 0 (Fig. 227).

Properties panel image
Fig. 227

Select the Insert Record button and in the Properties panel change the Value to Suggest link exchange (Fig. 228).

Properties panel value field image
Fig. 228

With the button still selected hit Ctrl+T on your keyboard once. Move your cursor to the end of input tag and type id="button". Now hit Enter on your keyboard to confirm changes and Save the file (Fig. 229).

Submit button properties image
Fig. 229

Now place your cursor anywhere within the table and click <form#form1> tag on the status bar to select the entire form (Fig. 230).

Select form image
Fig. 230

Press Ctrl+T on your keyboard once to open Edit tag option. Now change id="form1" to id="formsubmit" and hit Enter on your keyboard to confirm changes (Fig. 231). Save the file.

Form properties image
Fig. 231

Change the view to Code and identify the line which reads:

<td nowrap="nowrap" align="right">*Email:</td>

and add label to it, so it reads:

<td nowrap="nowrap" align="right"><label for="linkemail">*Email:</label></td>

On the next line place your cursor after name="linkemail" and type:

id="linkemail"

Now the entire two lines should read:

<td nowrap="nowrap" align="right"><label for="linkemail">*Email:</label></td>
<td><input type="text" name="linkemail" id="linkemail" value=""" size="32" /></td>

Do the same operation with all remaining fields (except the submit button) by adding label with the for attribute which should have the same value as name attribute of the field it is referring to and id attribute to its field with the same value.

Once you have done all this, change the view to Design and place your cursor within the first cell of the first raw of the table ­ the one with the *Email in it. Now click the <td> tag on the status bar to select this table cell (Fig. 232).

Select table cell image
Fig. 232

On your keyboard hit Ctrl+T once and change <td> tag with all its attributes (Fig. 233) to a simple <th> tag (Fig. 234).

Change td to th image
Fig. 233

Table header image
Fig. 234

Perform the same operation with all of the cells in the left column.

Once you′ve done all of them, change the view to Design and identify the line which reads:

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

Place your cursor at the end of this line and hit Enter on your keyboard to create a new line. On new line type the following:

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

Now identify the line which reads:

<td><textarea name="linkdescr" id="linkdescr" cols="50" rows="5"></textarea></td>
</tr>

Place your cursor after the closing </tr> tag and hit Enter to create a new line. On new line copy and paste the following:

<tr valign="baseline">
<th><label for="addcharl">Characters left:</label></th>
<td><input name="addcharl" id="addcharl" value="300" style="width: 30px" disabled="disabled" /></td>
</tr>

Place your cursor after the closing </form> tag and hit Enter to create a new line.
On new line copy and paste the following javascript:

<script type="text/javascript">
<!--
var supportsKeys = false
function tick() {
calcCharLeft(document.forms[0])
if (!supportsKeys) timerID = setTimeout("tick()",300)
}

function calcCharLeft(sig) {
clipped = false
maxLength = 300
if (document.form1.linkdescr.value.length > maxLength)
{
document.form1.linkdescr.value = document.form1.linkdescr.value.substring(0,maxLength)
charleft = 0
clipped = true
}
else
{
charleft = maxLength - document.form1.linkdescr.value.length
}
document.form1.addcharl.value = charleft
return clipped
}

tick();
//-->
</script>

Now we will apply sticky form fields functionality to our form.

To start with identify the following input field:

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

and change its value from an empty string to:

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

The entire input should now look like this:

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

Do the same with all remaining input fields (except the submit button) replacing the $_POST[‘linkemail’] with the relevant field′s name.

Now select the entire <select> section which reads:

<select name="linkcat" id="linkcat">
<?php
do {
?>
<option value="<?php echo $row_rsCategories['catid']?>" ><?php echo $row_rsCategories['catname']?></option>
<?php
} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));
?>
</select>

and replace it with the following:

<select name="linkcat" id="linkcat">
<option value=""
<?php
$OK = isset($_POST['linkcat']) ? true : false;
if ($OK && $_POST['linkcat'] == "") { ?>
selected="selected"
<?php } ?>
>...Choose category...</option>
<?php do { ?>
<option value="<?php echo $row_rsCategories['catid']?>"
<?php
if ($OK && $_POST['linkcat'] == $row_rsCategories['catid']) { ?>
selected="selected"
<?php } ?>
><?php echo $row_rsCategories['catname']?></option>
<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?>
</select>

What it basically does is it adds an extra <option> to be displayed as first one with the value="" and it also adds sticky form filed functionality to each, displayed <option> by adding selected="selected" if this specific category is selected while form is submitted.

For <textarea> place your cursor before the closing </textarea> tag and copy and paste the following:

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

Our sticky form fields functionality is now applied to our form.

Now we are going to add one of the Server Behaviors which checks if the entered url is already listed in our database. If it is then it will redirect visitor to links_already_exists.php page, where visitor is informed that this url has already been added to our system.

To do this change your view to Design and in the Server Behaviors section of the Application panel click + sign. From the list of options choose User Authentication > Check New Username (Fig. 235)

User Authentication image
Fig. 235

In the Check New Username window choose:

Username field: linkurl
If already exists, go to: links_already_exists.php
(Fig. 236).

Check new username image
Fig. 236

Click OK and Save the file.

Now we are going to add server side validation to our form.
Change view to Code and identify the line which reads:

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

Place your cursor at the end of this line and hit Enter on your keyboard to create a new line. Now copy and paste the following:

//regex to ensure no illegal characters in email address are provided
$checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

//form validation
if (($_POST['linkemail'] == "" || !preg_match($checkEmail, $_POST['linkemail'])) || $_POST['linkcat'] == "" || $_POST['linktitle'] == "" || $_POST['linkurl'] == "" || $_POST['linkrecip'] == "" || $_POST['linkdescr'] == "") {

if ($_POST['linkemail'] == "" || !preg_match($checkEmail, $_POST['linkemail'])) {
$mess = "<p>Please provide your valid email address</p>";
}
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['linkrecip'] == "") {
$mess .= "<p>Please provide reciprocal link</p>";
}
if ($_POST['linkdescr'] == "") {
$mess .= "<p>Please provide description.</p>";
}

} else {

Identify the line which reads:

$insertGoTo = "links_submitted.php";

Place your cursor after this line and hit Enter on your keyboard to create a new line.

On the new line we are going to copy the following code which will send us an email every time someone submits the link:

function sendEmail() {

$to = 'info@sebastiansulinski.co.uk'; //replace with your own email address
$subject = 'Link exchange request from my website';
$message = 'You have a new link exchange request';

$mailSent = mail($to, $subject, $message);

}

// send email
sendEmail();

Now identify the line which reads:

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

and after the curly brace place another one so it looks like this:

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

Wow! We have just finished our validation.

Now it is a good idea to provide some information to the visitor at the top of the submission form. Identify the line which reads:

<p id="title">Submit URL</p>

Place the cursor at the end of this line and hit Enter on your keyboard.
On new line type something like this (or whatever you really feel like) replacing link details with your own ones:

<p>If you would like to exchange link with us please copy and paste the following information into you listing page and submit the link exchange request form below.</p>

<div id="linkField">&lt;a href="http://www.sebastiansulinski.co.uk/" title="Web Designer East Sussex" target="_blank"&gt;Web Designer East Sussex&lt;/a&gt;&lt;br /&gt;Freelance web designer efficient in PHP, MySQL, XML, Ajax, CSS and JavaScript.</div>

Once you′ve done this, Save the file and this page is officially completed.
The only last thing we need to do to finish this tutorial is to provide some information on two other pages: links_submitted.php and links_already_exists.php.

Open links_submitted.php, go to Code view and identify the line which reads:

<?php include ('../includes/search_engine.php'); ?>

Place your cursor at the end of this line and hit Enter on your keyboard to create a new line. On new line type:

<p id="title">Submission received</p>
<p>Your link request has been received.<br />You will be notified by email once it has been approved.</p>

Save and close this file.

Now open links_already_exists.php, identify the line which reads:

<?php include ('../includes/search_engine.php'); ?>

Place your cursor at the end of this line and hit Enter to create a new line.
On new line type:

<p id="title">Record already exists</p>
<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>

Now identify the line which reads:

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

Create new line and copy and paste the following:

<script type="text/javascript">

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

</script>

Save and close the file.

And here it is ­ THE END of this, rather long tutorial.

I hope you enjoyed this tutorial ­ feel free to post any comments or thoughts.
In the meantime take care and keep checking this site for new, oncoming tutorials.

Sebastian Sulinski

<<Latest Links 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