Thanks alot for your help on this, I've added the code, but cannot get "Message_Creator" to work as " " blank values, so have changed to "Please select" but of course, the field will not be seen as empty. How do I get the script to see that "Please select", the default value cannot be left.
Hope you can help.
Jonathan
New Code Below...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<style>
body {
color : black;
background-color : white;
background-image : ;
background-position : 0% 0%;
background-repeat : repeat-x;
background-attachment : fixed;
font-family : Arial, Verdana;
font-size : 12px;
font-weight : bold;
text-align : left;
}
form {
color : ;
border-color : blue;
}
table {
color : black;
background-color : white;
background-image : ;
background-position : 0% 0%;
background-repeat : repeat-x;
background-attachment : fixed;
font-family : Arial, Verdana;
font-size : 12px;
font-weight : ;
text-align : left;
}
a:link {
text-decoration : none;
color : #003366;
}
a:visited {
text-decoration : none;
color : #003366;
}
a:hover {
text-decoration : underline;
color : blue;
}
</style>
<script language="javascript" type="text/javascript">
function formValidate(form) {
if(form.message_creator.value == "Please select") {
alert('Please select a Message Creator')
form.message_creator.focus();
return false;
}
if(form.message_title.value == "") {
alert('Please input a Message Title');
form.message_title.focus();
return false;
}
if(form.message_text.value == "") {
alert('Please input Message Body');
form.message_text.focus();
return false;
}
return true;
}
</script>
<body>
<h2>Stop Press - Post</h2>
<table>
<tr>
<td><img src="Images/nav_CloseChilds_L1_154.gif" width="15" height="14" border="0"></td>
<td><a target="content"a href="stop_press_menu.html">Back to Menu</a> or </td>
<td><a target="content"a href="stop_press_get.php">View Posts</a></td>
</tr>
</table>
<BR>
<?php
// Test for user input
if (empty($message_creator) || empty($message_title) || empty ($message_text))
{
?>
<body bgcolor="#ffffff">
<form method="post" action="stop_press_post_dev.php" onSubmit="return formValidate(this);">
<?
// include 'clean.inc';
function selectDistinct ($connection,
$tableName,
$columnName,
$pulldownName,
$additionalOption,
$defaultValue)
{
$defaultWithinResultSet = FALSE;
// Query to find distinct values of $columnName
// in $tableName
$distinctQuery = "SELECT DISTINCT $columnName
FROM $tableName
ORDER by $columnName";
// Run the distinctQuery on the databaseName
if (!($resultId = @ mysql_query ($distinctQuery,
$connection)))
showerror();
// Retrieve all distinct values
$i = 0;
while ($row = @ mysql_fetch_array($resultId))
$resultBuffer[$i++] = $row[$columnName];
// Start the select widget
echo "\n<select name=\"$pulldownName\">";
// Is there an additional option?
if (isset($additionalOption))
// Yes, but is it the default option?
if ($defaultValue == $additionalOption)
// Show the additional option as selected
echo "\n\t<option selected>$additionalOption";
else
// Just show the additional option
echo "\n\t<option>$additionalOption";
// check for a default value
if (isset($defaultValue))
{
// Yes, there's a default value specified
// Check if the defaultValue is in the
// database values
foreach ($resultBuffer as $result)
if ($result == $defaultValue)
// Yes, show as selected
echo "\n\t<option selected>$result";
else
// No, just show as an option
echo "\n\t<option>$result";
} // end if defaultValue
else
{
// No defaultValue
// Show database values as options
foreach ($resultBuffer as $result)
echo "\n\t<option>$result";
}
echo "\n</select>";
} // end of function
// Connect to the DBMS
if (!($connection = @ mysql_connect($hostname,
$username,
$password)))
die("Could not connect to database");
if (!mysql_select_db("intranet"))
showerror();
echo "\nMessage Creator:";
// Produce the select list
// Parameters:
// 1: Database connection
// 2. Table that contains values
// 3. Attribute that contains values
// 4. <SELECT> element name
// 5. An additional non-database value
// 6. Optional <OPTION SELECTED>
selectDistinct($connection,
"internal_people",
"name",
"message_creator",
"Please select",
"");
?>
<br>
<br>
Message Subject:
<br>
<input type="text" name="message_title" size="60" maxlength="60" />
<br>
Message Body:
<br>
<textarea name="message_text" rows="15" cols="69" wrap="physical"></textarea>
<br>
<input type="hidden" name="message_ip" value="<?php echo $REMOTE_ADDR; ?>" />
<input type="hidden" name="dept_key" value="RE">
<br>
<font color="red"<b>All fields must be completed for the message to post</b></p>
<input type="submit" value="Post Message">
</form>
<?php
}
else
{
if (!($connection = @ mysql_connect($hostname,
$username,
$password)))
die("Could not connect to database");
if (!mysql_select_db("intranet", $connection))
showerror();
$insertQuery = "INSERT INTO stop_press VALUES
(NULL, " .
"\"" . $dept_key ."\", " .
"\"" . $message_creator ."\", " .
"\"" . $message_title ."\", " .
"\"" . $message_text ."\", " .
"\"" . $message_ip ."\", " .
"NOW())";
if ((@ ($insertQuery,
$connection))
&& @ mysql_affected_rows() == 1)
echo '<h5>Message posted successfully - Thank you</h5>';
else
showerror();
}//if else empty()
?>
</body>
</html>