Hi guys
I would like to set a default value for the drop down menu incase a user forgets to select an option from there. At the moment it is just inserting “choose option/category” if the user forgets to select something. I would like this to be applied to the category field and the loan field
[code=php]<?php session_start(); ?>
<?php // suppress or turn off notice errors or warnings
error_reporting (E_ALL ^ E_NOTICE); ?>
<?php require_once(“includes/functions.php”);
include_once(“includes/functions_two.php”);
if (!isset($_SESSION[‘camnumber’])) {
redirect_to (“index2.php”);
}
?>
<html>
<head>
<title>Listing page</title>
</head>
<body>
<?php include(“includes/header.php”); ?>
<table id= “structure”>
<tr>
<td id=”navigation”>
<br/><a href = “member.php”> Back to Menu Page</a><br/>
<br/><a href= “logout.php”>Log out</a>
</td>
<td id= “page”>
<h2>Adding book details</h2>
<?php
// checking for submit
$submit = $_POST[‘submit’];
// form data and stripping of html tags
$title = strip_tags($_POST[‘title’]);
$author = strip_tags($_POST[‘author’]);
$edition = strip_tags($_POST[‘edition’]);
//$publicationdate = strip_tags($_POST[‘publicationdate’]);
$publicationdate=strip_tags($_POST[‘publicationdate’]);
//$aDate_parts=preg_split(“/[s-]+/”,$publicationdate);
$isbnnumber = strip_tags($_POST [‘isbnnumber’]);
$condition = strip_tags($_POST[‘condition’]);
$price = strip_tags($_POST[‘price’]);
$category = strip_tags($_POST[‘category’]);
$loan = strip_tags($_POST[‘loan’]);
/*function is_date($publicationdate){
$stamp=strtotime($publicationdate);
if(!is_numeric($stamp))
{return FALSE;
}
$month=date(‘m’,$stamp);
$day=date(‘d’,$stamp);
$year=date(‘Y’,$stamp);
$response=”Thanks”;
if(checkdate($month,$day,$year))
{
return $response;
}
return FALSE;
}*/
$camnumber = $_SESSION[‘camnumber’];
if($submit)
{
// user registration by connecting to database
$connect = mysql_connect(“localhost”, “”, “”);
mysql_select_db (“book_trade2”);
$isbncheck = mysql_query (“SELECT isbnnumber FROM books WHERE isbnnumber =’$isbnnumber ‘”);
$count = mysql_num_rows($isbncheck);
if ($count!=0)
{
echo (“<span style=’color:red’ name=’PHPSpan’><b>ISBN Number has to be unique</b></span>”);
}
else{
// check for that all fields have been entered
if ($title&&$author&&$isbnnumber&&$condition&&$price&&$category&&$camnumber&&$loan)
{
//checks that a digit is entered and rounds it off if more than two values are entered after the decimal place.
if (!is_numeric($price))
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Price must be a an interger</b></span>”;
}
else
{
// check for character length of isbn number
if (strlen($isbnnumber)>13||strlen($isbnnumber)<13)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Length of ISBN Number should not be more or less than 13 characters</b></span>”;
}
else
{
// check title name and author length
if (strlen($title)>50||strlen($author)>60)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Length of Title and Author is too long</b></span>”;
}
else
{
// check the details submitted if this field is not empty
if (!empty($_POST[‘edition’])&& strlen($edition)<2||strlen($edition)>6)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Edition must be between 6 and 2 characters</b></span>”;
}
else{
//if the date field is not empty check the details submitted in it
if (!empty($_POST[‘publicationdate’]))
{
$date_val = date_validate($publicationdate);
}
//search for the date within the string to validate it
$check_date = strpos($date_val,”Invalid”);
if($check_date === false) {
// code to connect to database was here
$queryreg = mysql_query(”
INSERT INTO books VALUES(”,’$title’,’$author’,’$edition’, ‘$date_val’,’$isbnnumber’,’$condition’,’$price’,’$category’,’$loan’,’$camnumber’)
“);
die(“You book has been added <a href =’index2.php’> Return to login page</a>”);
//die (“You book has been added <a href =’index2.php’> Return to login page</a>”);
}
else{
echo “$date_val”;
}
}
}
}
}
}
else{
echo “<span style=’color:red’ name=’PHPSpan’><b>Please fill in all fields</b></span><br />”;
}
}
}
?>
<form action=’listing.php’ method= ‘POST’>
<table>
<tr>
<td>
Title
</td>
<td>
<input type=’text’ size=’33’ name=’title’ value= “<?php echo $title; ?>”>
</td>
</tr>
<tr>
<td>
Author
</td>
<td>
<input type=’text’ size=’33’ name=’author’ value= “<?php echo $author; ?>”>
</td>
</tr>
<tr>
<td>
Edition
</td>
<td>
<input type=’text’ size=’33’ name=’edition’value= “<?php echo $edition;?>”>
</td>
</tr>
<tr>
<td>
Publication Date
</td>
<td>
<input type=’txtdate’ size=’33’ name=’publicationdate’ value= “<?php echo $publicationdate; ?>”>
<span class=”date”>(yyyy/mm/dd)
</td>
</tr>
<tr>
<td>
ISBN Number
</td>
<td>
<input type=’text’ size=’33’ name=’isbnnumber’ value= “<?php echo $isbnnumber; ?>”>
</td>
</tr>
<tr>
<td>
Condition
</td>
<td>
<input type=’text’ size=’33’ name=’condition’value= “<?php echo $condition; ?>”>
</td>
</tr>
<tr>
<td>
Price £
</td>
<td>
<input type=’text’ size=’33’ name=’price’value= “<?php echo $price; ?>”>
</td>
</tr>
<tr>
<td>
Category
<td colspan=’2′>
<select name= ‘category’>
<option value= ‘Database’>Database</option>
<option value= ‘Multimedia & design’>Multimedia & design</option>
<option value= ‘Structured programming’>Structured Programming</option>
<option value= ‘Software engineering’>Software engineering</option>
<option value= ‘Projects’>Projects</option>
<option value= ‘Networks’>Networks</option>
<option value= ‘Human computer interface design’>Human Computer Interface Design</option>
<option value= ‘Systems analysis’>Systems Analysis</option>
<option value= ‘Web authoring’>Web Authoring</option>
<option value= ‘3d Graphics & animation’>3d Graphics & Animation</option>
<option value= ‘Web servers’>Web Servers</option>
<option value= ‘Object oriented programming’>Object Oriented Programming</option>
<option value= ‘Unix sytems’>Unix Sytems</option>
<option value= ‘Other’>Other</option>
<option value= ‘Choose’ selected>Choose Category</option>
</select>
</tr>
</td>
<tr>
<td>
Available for loan
<td cols=’2′>
<select name=’loan’>
<option value= ‘Yes’>Yes</option>
<option value= ‘No’>No</option>
<option value= ‘Choose’ selected>Choose Option</option>
</select>
</tr>
</td>
<tr>
<td><input type=’submit’ name=’submit’ value=’Add your book’>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php include(“includes/footer.php”); ?>
Thanks