Hi
Any help appreciated.
I am new to PHP & MYSQL,
I am looking for the following code or advice as to where i could find info re creating same.
A drop down menu and input box where when the user selects an option and enters a number in a text area the value is sent to a DB table/field.
Example:
Drop down menu with 5 options - phone , mobile, fax, voip ext,etc - when the user selects mobile they then enter a number in an input box and hits submit the number posts to the mobile field in the database table, or user selects phone enters a number in a text field and the number is posted to the phone field in the database table.
I have this but don`t know how to do the above - the full form is below.
Phone Fax Number:
<select name="number" action="message.php" method="post">
<option>Phone</option>
<option>Fax</option>
<option>Mobile</option>
<option>Voip</option>
<option>Phone 2</option>
</select>
<input name="" type="text" value="">
Thanks for any help
Jason
<?php
// connect to the database
include('dbconnect.php');
include("variable.php");
$error = false;
// run this only, once the user has hit the "Add Contact" button
if (isset($_POST['addcontact'])) {
// assign form inputs
$salutation = $_POST['salutation'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone1 = $_POST['phone1'];
$phone2 = $_POST['phone2'];
$phone3 = $_POST['phone3'];
$phone4 = $_POST['phone4'];
$phone5 = $_POST['phone5'];
$fax = $_POST['fax'];
$mobilephone = $_POST['mobilephone'];
$number = $_POST['phone_select'];
$voipphone = $_POST['voipphone'];
$email = $_POST['email'];
$street1 = $_POST['street1'];
$street2 = $_POST['street2'];
$street3 = $_POST['street3'];
$city = $_POST['city'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$category = $_POST['category'];
$type = $_POST['type'];
$department = $_POST['department'];
$company = $_POST['company'];
// validate inputs
if ( !empty($firstname) && !empty($lastname) ) {
// add member to database
$query = "INSERT INTO contacts (salutation,firstname,lastname,phone1,phone2,phone3,phone4,phone5,fax,mobilephone,voipphone,email,street1,street2,street3,city,county,postcode,country,category,type,department,company) VALUES ('".$salutation."','".$firstname."','".$lastname."','".$phone1."','".$phone2."','".$phone3."','".$phone4."','".$phone5."','".$fax."','".$mobilephone."','".$voipphone."','".$email."','".$street1."','".$street2."','".$street3."','".$city."','".$county."','".$postcode."','".$country."','".$category."','".$type."','".$department."','".$company."')";
$result = $database->query($query);
$database->disconnect();
$message = "\"".$firstname." ".$lastname."\" has been successfully added.";
Header("Location: listcontacts.php");
exit;
}
else {
$error = true; // input validation failed
}
}
?>
<html>
<head>
<title>Add a Contact</title>
</head>
<body>
Add a Contact | <a href="listcontacts.php">My Contacts</a>
<h1>Add a Contact</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
if ( !empty($message) ) {
echo '<span style="color:green">',$message,'</span><br><br>',"\n";
}
?>
<?php
if ( $error && empty($firstname) ) {
echo '<span style="color:red">Error! Please enter a first name.</span><br>',"\n";
}
?>
<p>Salutation:
<select name="salutation">
<option>Mr</option>
<option>Ms</option>
<option>Mrs</option>
<option>Dr</option>
</select>
<br>
<p>First Name:
<input name="firstname" type="text" value=""> Last Name:
<input name="lastname" type="text" value="">
<br>
<br>
<?php
if ( $error && empty($lastname) ) {
echo '<span style="color:red">Error! Please enter a last name.</span><br>',"\n";
}
?>
Phone Fax Number:
<select name="number" action="message.php" method="post">
<option>Phone</option>
<option>Fax</option>
<option>Mobile</option>
<option>Voip</option>
<option>Phone 2</option>
</select>
<input name="" type="text" value="">
<br>
<br>
E-Mail:
<input name="email" type="text" value="">
<br>
<br>
Address:<br>
Street 1:
<input name="street1" type="text" value="">
Street 2:
<input name="street2" type="text" value="">
Street 3:
<input name="street3" type="text" value="">
<br>
<br>
City:
<input name="city" type="text" value="">
County:
<input name="county" type="text" value="">
Post Code:
<input name="postcode" type="text" value="">
Country:
<select name="country">
<option>Ireland</option>
<option>United Kingdom</option>
<option>France</option>
<option>Germany</option>
<option>spain</option>
<option>Portugal</option>
</select>
<br>
<br>
Category:
<select name="category">
<option>Personel</option>
<option>Business</option>
</select>
Contact Type:
<select name="type">
<option>Customer</option>
<option>Supplier</option>
<option>Employee</option>
</select>
Department:
<select name="department">
<option>Sales</option>
<option>Accounts</option>
<option>Support</option>
<option>Purchasing</option>
</select>
<br>
<br>
Select Company:
<select name="company">
<option></option>
<option>JmcSoft Distribution</option>
<option>Test Company</option>
</select>
<br>
<br>
Add New Company:
<input type="text" name="addcompany" value="">
<br>
<br>
<br>
<input type="submit" name="addcontact" value="SAVE">
</form>
</body>
</html>