I'm using HTMLarea so the only thing telling the textarea it's a HTMLarea is the id. But here's the code i'm using to add/update my database.
Code: Select all
<?php # Script - add_home.php
// This page allows the administrator to add and update a home (product).
//Require authentication.
require_once ('../../authentication.php');
$page_title = 'Staffordshire Open Studios - Add/Edit an Open Studio Artist';
include_once ('../includes/header_admin.html');
//Check for authorization.
if (!$authorized) {
echo '<p><font color="red">Please enter a valid username and password! Click <a href="administration.php">here</a> to try again!</font></p>';
} else {
require_once ('../../mysql_connect.php'); // conect to the database.
function get_home_record($studioartist_id)
{
$query = "select * from openstudiosartists where studioartist_id = '$studioartist_id'";
if (!$result = mysql_query($query))
{
die("There was a problem with query::$query - " . mysql_error());
}
return(mysql_fetch_array($result));
}
/*
function query_select($name, $query, $default='')
{
$result = mysql_query($query);
if (!$result)
return('<select name="category" id="category">
<option value="New Home" selected >New Home</option>
<option value="Used Home">Used Home</option>
</select>');
$select = "<SELECT NAME=\"$name\">";
$select .= "<OPTION VALUE=\"\">-- Choose --</OPTION>";
for ($i=0; $i < mysql_numrows($result); $i++) {
$opt_code = mysql_result($result, $i, 0);
$select .= "<OPTION VALUE=\"$opt_code\"";
if ($opt_code == $default) {
$select .= ' SELECTED';
}
$select .= ">[$opt_code] $opt_desc</OPTION>";
}
$select .= "</SELECT>\n";
return($select);
}
*/
if (isset($HTTP_GET_VARS['studioartist_id']))
$sa = get_home_record($HTTP_GET_VARS['studioartist_id']);
if (isset($_POST['submit'])) { // Handle the form.
// Validate the name, description, craft, area, address, tel, fax, email, website, mobile, opening, car parking, demonstrations, disabled access, toilets, disabled toilets, refreshments, gallery and schools liaison.
//Check for a name.
if (!empty($_POST['name'])) {
$n = escape_data($_POST['name']);
} else {
$n = FALSE;
echo '<p><font color="red">Please enter the artists name!</font></p>';
}
// Check for a username.
if (eregi ("^[[]_]{4,40}$", stripslashes(trim($_POST['username'])))) {
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo '<p><font color="red">Please enter a valid username!</font></p>';
}
// Check for a password and match against the confirmed password.
if (eregi ("^[[]]{4,30}$", stripslashes(trim($_POST['password1'])))) {
if ($_POST['password1'] == $_POST['password2']) {
$p = escape_data($_POST['password1']);
} else {
$p = FALSE;
echo '<p><font color="red">Your password did not match the confirmed password!</font></p>';
}
} else {
$p = '';
}
// Check for description
if(!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = FALSE;
echo '<p><font color="red">Please enter a description!</font></p>';
}
// Check for area
if(!empty($_POST['location'])) {
$l = escape_data($_POST['location']);
} else {
$l = '';
}
// Check for address
if(!empty($_POST['address'])) {
$a = escape_data($_POST['address']);
} else {
$a = FALSE;
echo '<p><font color="red">Please enter an address</font></p>';
}
// Check for tel
if(!empty($_POST['tel'])) {
$t = escape_data($_POST['tel']);
} else {
$t = '';
}
// Check for home tel
if(!empty($_POST['home_tel'])) {
$ht = escape_data($_POST['home_tel']);
} else {
$ht = '';
}
// Check for a fax
if(!empty($_POST['fax'])) {
$f = escape_data($_POST['fax']);
} else {
$f = '';
}
// Check for an email (not required).
if (eregi ("^[[]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = '';
}
// Check for a website (not required).
if (!empty($_POST['website'])) {
$w = escape_data($_POST['website']);
} else {
$w = '';
}
// Check for a website (not required).
if (!empty($_POST['website2'])) {
$wtw = escape_data($_POST['website2']);
} else {
$wtw = '';
}
// Check for a website (not required).
if (!empty($_POST['website3'])) {
$wth = escape_data($_POST['website3']);
} else {
$wth = '';
}
// Check for a website (not required).
if (!empty($_POST['website4'])) {
$wf = escape_data($_POST['website4']);
} else {
$wf = '';
}
// Check for a mobile (not required).
if (!empty($_POST['mobile'])) {
$m = escape_data($_POST['mobile']);
} else {
$m = '';
}
// Check for opening times (not required).
if (!empty($_POST['open'])) {
$o = escape_data($_POST['open']);
} else {
$o = '';
}
// Check for directions (not required).
if (!empty($_POST['directions'])) {
$di = escape_data($_POST['directions']);
} else {
$di = '';
}
// Check for car parking (not required).
if (!empty($_POST['carparking'])) {
$cp = escape_data($_POST['carparking']);
} else {
$cp = '';
}
// Check for demonstrations (not required).
if (!empty($_POST['demonstrations'])) {
$dm = escape_data($_POST['demonstrations']);
} else {
$dm = '';
}
// Check for disabled access (not required).
if (!empty($_POST['disabledaccess'])) {
$da = escape_data($_POST['disabledaccess']);
} else {
$da = '';
}
// Check for toilets (not required).
if (!empty($_POST['toilets'])) {
$tl = escape_data($_POST['toilets']);
} else {
$tl = '';
}
// Check for disabled toilets (not required).
if (!empty($_POST['disabledtoilets'])) {
$dt = escape_data($_POST['disabledtoilets']);
} else {
$dt = '';
}
// Check for refreshments (not required).
if (!empty($_POST['refreshments'])) {
$r = escape_data($_POST['refreshments']);
} else {
$r = '';
}
// Check for a gallery (not required).
if (!empty($_POST['gallery'])) {
$g = escape_data($_POST['gallery']);
} else {
$g = '';
}
// Check for school liaison (not required).
if (!empty($_POST['schoolliaison'])) {
$sl = escape_data($_POST['schoolliaison']);
} else {
$sl = '';
}
$query = "SELECT studioartist_id FROM openstudiosartists WHERE username='$u' AND studioartist_id != '$studioartist_id'";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 0) { // Available.
if (isset($HTTP_POST_VARS['studioartist_id']) && $HTTP_POST_VARS['studioartist_id']!='')
{ // It's an update
$studioartist_id = $HTTP_POST_VARS['studioartist_id'];
$query = "update openstudiosartists set
name = '$n',
username = '$u',
description = '$d',
location = '$l',
address = '$a',
tel = '$t',
home_tel = '$ht',
fax = '$f',
mobile = '$m',
email = '$e',
website = '$w',
website2 = '$wtw',
website3 = '$wth',
website4 = '$wf',
open = '$o',
directions = '$di',
carparking = '$cp',
demonstrations = '$dm',
disabledaccess = '$da',
toilets = '$tl',
disabledtoilets = '$dt',
refreshments = '$r',
gallery = '$g',
schoolliaison = '$sl'
where studioartist_id = $studioartist_id";
} else { // It's a new story
if ($n && $d && $a && $u && $p) {
// Add the home to the database.
$query = "INSERT INTO openstudiosartists(name, description, location, address, tel, home_tel, fax, mobile, email, website, website2, website3, website4, open, directions, carparking, demonstrations, disabledaccess, toilets, disabledtoilets, refreshments, gallery, schoolliaison, username, password)
VALUES('$n', '$d', '$l', '$a', '$t', '$ht', '$f', '$m', '$e', '$w', '$wtw', '$wth', '$wf', '$o', '$di', '$cp', '$dm', '$da', '$tl', '$dt', '$r', '$g', '$sl', '$u', PASSWORD('$p'))";
} else { // Failed a test.
/******************************************
* THIS SHOULD BE DIE SEEING AS QUERY DOES
* NOT EXIST HERE
*****************************************/
die('<p><font color="red">Please check that you have entered data for the following fields: <br>Name<br>Description<br>Address<br>Username<br>Password<br><br><a href="javascript:history.go(-1)">back ></a></font></p>');
}
/**********************************************
* CLOSE THE ISSET CHECK HERE AND RUN THE QUERY
* OUTSIDE OF IT
*********************************************/
}
if ($result = mysql_query($query)) { // Worked.
if (isset($HTTP_POST_VARS['studioartist_id']) && $HTTP_POST_VARS['studioartist_id']!='') {
echo 'The participating artist has been successfully updated. <a href="artist_more.php?studioartist_id='.$HTTP_POST_VARS['studioartist_id'].'" class="link">Back ></a>';
} else {
echo 'The participating artist has been successfully added. <a href="participating_artists.php" class="link">Back ></a>';
}
} else { // If the query did not run OK.
die('<p><font color="red">Your submission could not be processed due to a system error: ' . mysql_error() . '.</font></p>');
}
} else {
// The username is not available.
echo '<font color="red">That username is already taken.</font><br><br><a href="javascript:history.go(-1)">back ></a>';
}
} else { // Display the form.
?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="studioartist_id" value="<?php print $HTTP_GET_VARS['studioartist_id'];?>">
<input type="hidden" name="MAX_FILE_SIZE" value="77524288">
<h1>Add/Edit an Open Studio Artist</h1><br>
Fill out the form to add or edit an Open Studios Artist:
<br>
<br><span class="red">*</span>_ Denotes Required Field<br>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="180" height="26" align="left" valign="top"><strong>Artist Name & Area Code:</strong> <span class="red">*</span></td>
<td align="left" valign="top"><input name="name" class="form_fields" type="text" value="<?php print $sa['name'];?>" size="30" maxlength="100"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Username:</strong> <span class="red">*</span></td>
<td align="left" valign="top"><input name="username" class="form_fields" type="text" value="<?php print $sa['username']; if (isset($_POST['username'])) echo $_POST['username'];?>" size="30" maxlength="30" />
<br>
<small>Use only letters, numbers, and the underscore. Must be between 4 and 30 characters long.</small></td>
</tr>
<?php if ($sa['studioartist_id']) {
} else {
print '<tr>
<td height="26" align="left" valign="top"><strong>Password:</strong> <span class="red">*</span></td>
<td align="left" valign="top">
<input type="password" name="password1" class="form_fields" size="30" maxlength="30"/>
<br><small>Use only letters and numbers. Must be between 4 and 30 characters long.</small></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Confirm Password: </strong><span class="red">*</span></td>
<td align="left" valign="top"><input type="password" class="form_fields" name="password2" size="30" maxlength="30" /></td>
</tr>
';
}
?>
<tr>
<td height="26" align="left" valign="top"><strong>Short description:</strong> <span class="red">*</span><!-- <br>
<span class="small">Please type text directly into the textarea, or copy and paste from Notepad. <br>
Do not take text directly <br>
from Microsoft Word.</span> --></td>
<td align="left" valign="top"> <textarea name="description" class="form_fields" wrap="hard" cols="58" rows="8" id="description" onKeyPress="textCounter(this,this.form.counter,600);"><?php print $sa['description'];?></textarea>
</td></tr>
<tr>
<td height="26" align="left" valign="top"> </td>
<td align="left" valign="top"><!-- <input
type="text"
name="counter"
maxlength="3"
size="3"
value="600"
onBlur="textCounter(this.form.counter,this,600);"> -->
Approximately one paragraph of text</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Area:</strong></td>
<td align="left" valign="top"><?php if ($sa['studioartist_id']) {
if ($sa['location'] == 'SOUTH') {
print' <select name="location" id="location" class="form_fields">
<option value="SOUTH" selected >South</option>
<option value="CENTRAL">Central</option>
<option value="NORTH">North</option>
</select>';
} else if ($sa['location'] == 'CENTRAL') {
print' <select name="location" id="location" class="form_fields">
<option value="CENTRAL" selected >Central</option>
<option value="SOUTH">South</option>
<option value="NORTH">North</option>
</select>';
} else {
print' <select name="location" id="location" class="form_fields">
<option value="NORTH" selected >North</option>
<option value="SOUTH">South</option>
<option value="CENTRAL">Central</option>
</select>';
}
}else {
echo '<select name="location" id="location" class="form_fields">
<option value="SOUTH" selected >South</option>
<option value="CENTRAL">Central</option>
<option value="NORTH">North</option>
</select>';
}?></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Address:</strong> <span class="red">*</span></td>
<td align="left" valign="top"><textarea name="address" class="form_fields" cols="35" rows="5"><?php print $sa['address'];?></textarea></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Telephone no:</strong></td>
<td align="left" valign="top"><input type="text" name="tel" class="form_fields" size="30" maxlength="15" value="<?php print $sa['tel'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Home Telephone no: </strong></td>
<td align="left" valign="top"><input type="text" name="home_tel" class="form_fields" size="30" maxlength="15" value="<?php print $sa['home_tel'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Fax no:</strong></td>
<td align="left" valign="top"><input type="text" name="fax" class="form_fields" size="30" maxlength="15" value="<?php print $sa['fax'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Mobile no:</strong></td>
<td align="left" valign="top"><input type="text" name="mobile" class="form_fields" size="30" maxlength="15" value="<?php print $sa['mobile'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Email:</strong></td>
<td align="left" valign="top"><input type="text" name="email" class="form_fields" size="30" maxlength="80" value="<?php print $sa['email'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Website:</strong></td>
<td align="left" valign="top"><input type="text" name="website" class="form_fields" size="30" maxlength="80" value="<?php print $sa['website'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Website no.2: </strong></td>
<td align="left" valign="top"><input type="text" name="website2" class="form_fields" size="30" maxlength="80" value="<?php print $sa['website2'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Website no. 3: </strong></td>
<td align="left" valign="top"><input type="text" name="website3" class="form_fields" size="30" maxlength="80" value="<?php print $sa['website3'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Website no. 4: </strong></td>
<td align="left" valign="top"><input type="text" name="website4" class="form_fields" size="30" maxlength="80" value="<?php print $sa['website4'];?>"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Opening times:</strong></td>
<td align="left" valign="top"><input name="open" type="text" class="form_fields" value="<?php print $sa['open'];?>" size="30" maxlength="100"></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Directions:</strong></td>
<td align="left" valign="top"><textarea name="directions" class="form_fields" cols="35" rows="5"><?php print $sa['directions'];?></textarea></td>
</tr>
<?php if ($sa['studioartist_id'])
{
print '<tr>
<td height="26" align="left" valign="top"><strong>Car parking :</strong></td>
<td align="left" valign="top">';
if ($sa['carparking']) {
print '<select name="carparking" id="carparking" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="carparking" id="carparking" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print '</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Demonstrations:</strong></td>
<td align="left" valign="top">';
if ($sa['demonstrations']) {
print '<select name="demonstrations" id="demonstrations" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="demonstrations" id="demonstrations" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Disabled Access :</strong></td>
<td align="left" valign="top">';
if ($sa['disabledaccess']) {
print '<select name="disabledaccess" id="disabledaccess" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="disabledaccess" id="disabledaccess" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Toilets:</strong></td>
<td align="left" valign="top">';
if ($sa['toilets']) {
print '<select name="toilets" id="toilets" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="toilets" id="toilets" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Disabled toilets:</strong></td>
<td align="left" valign="top">';
if ($sa['disabledtoilets']) {
print '<select name="disabledtoilets" id="disabledtoilets" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="disabledtoilets" id="disabledtoilets" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Refreshments:</strong></td>
<td align="left" valign="top">';
if ($sa['refreshments']) {
print '<select name="refreshments" id="refreshments" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="refreshments" id="refreshments" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Gallery:</strong></td>
<td align="left" valign="top">';
if ($sa['gallery']) {
print '<select name="gallery" id="gallery" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="gallery" id="gallery" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Schools Liaison :</strong></td>
<td align="left" valign="top">';
if ($sa['schoolliaison']) {
print '<select name="schoolliaison" id="schoolliaison" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select>';
} else {
print '<select name="schoolliaison" id="schoolliaison" class="form_fields">
<option value="" selected >No</option>
<option value="yes">Yes</option>
</select>';
}
print'</td>
</tr>';
} else {
print '<tr>
<td height="26" align="left" valign="top"><strong>Car parking :</strong></td>
<td align="left" valign="top">
<select name="carparking" id="carparking" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Demonstrations:</strong></td>
<td align="left" valign="top"><select name="demonstrations" id="demonstrations" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Disabled Access :</strong></td>
<td align="left" valign="top"><select name="disabledaccess" id="disabledaccess" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Toilets:</strong></td>
<td align="left" valign="top"><select name="toilets" id="toilets" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Disabled toilets:</strong></td>
<td align="left" valign="top"><select name="disabledtoilets" id="disabledtoilets" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Refreshments:</strong></td>
<td align="left" valign="top"><select name="refreshments" id="refreshments" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Gallery:</strong></td>
<td align="left" valign="top"><select name="gallery" id="gallery" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
<tr>
<td height="26" align="left" valign="top"><strong>Schools Liaison :</strong></td>
<td align="left" valign="top"><select name="schoolliaison" id="schoolliaison" class="form_fields">
<option value="yes" selected >Yes</option>
<option value="">No</option>
</select></td>
</tr>
';
}
?>
<tr align="center">
<td valign="top" colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form><!-- End of Form -->
<?php
} //End of main conditional.
}
include_once ('../includes/footer_nothing.html'); // Require the HTML footer.
?>
</body>
</html>
When the user updates the description box in HTML it adds random spaces and characters. But if they click to update in code mode it updates fine