MySQL:(PHP) UPDATE Query issue - php

I have an UPDATE Query in MySQL
UPDATE users
SET fname='$fname',lname='$lname',username='$user',password='$pass',role='$role',status=$status
where id=$id
It works perfectly when I run it in Phpmyadmin by giving values manually but it gives me an error message when I use it in PHP Page.
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
The error is generated because I am doing echo mysql_error() I am getting values from the FORM like this;
$id=$_POST['id'];
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$user=$_POST['txt_user'];
$pass=$_POST['txt_pass'];
$role=$_POST['txt_role'];
$status=$_POST['status'];
Frankly I sound like a stupid asking such a simple question, but I am stuck and need a bit of help. Thanks
FORM HTML
<div id="cuntable" style=" width:400px; margin:0 auto;">
<div class="CSSTableGenerator">
<form name="userform" action="updateuser.php" method="post">
<table >
<tr>
<td colspan="2"> Edit / Modify User Details </td>
</tr>
<tr>
<td>First Name </td>
<td><input type="text" name="txt_fname" placeholder="<?php echo $row[1];?>" /></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="text" name="txt_lname" placeholder="<?php echo $row[2];?>" /></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="txt_user" placeholder="<?php echo $row[3];?>"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="txt_pass" placeholder="<?php echo $row[4];?>" /></td>
</tr>
<tr>
<td>Username</td>
<td>
<select name="txt_role">
<option value=""> Select User Role </option>
<option value="user"> User </option>
<option value="admin">Administrator</option>
<option value="operator">Operator</option>
<option value="accountant">Accountant </option>
</select>
</td>
</tr>
<tr>
<td> Status </td>
<td>
<select name="status">
<option value="1"> Active </option>
<option value="0"> Suspended </option>
</select>
</td>
</tr>
</table>
</div>
<br />
<input type="submit" value=" ADD USER " />
<input type="hidden" name="txt_id" value="<?php echo $row[0];?>"
</form>

Related

Check if record exists and autofill the id from mysql table

When user fills the form, if LinkedIn Id already exists, it should throw an error saying LinkedIn Id already exists..
Form is not saving data if user does not enter ContactID. ContactID is an auto-increment field in MySQL table. Since more than one user works on the same form at the same time, I want ContactID to be auto-filled by the next available number from MySQL table.
Here, is my HTML form code and following, the PHP code. If you require any other details to debug, please ask.
<html>
<body>
<form method="post" action="demo.php">
<link rel="stylesheet" href="contact_css.css">
<!--Create a table -->
<table>
<tr><td><b>Contact Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>ContactID</td>
<td><input type="text" name="ContactID"></td>
</div>
<div class="rightside">
<td>ContactOwner</td>
<!-- <td><input type="text" name="ContactOwner"></td>-->
<td><select name="ContactOwner">
<option value="None">None</option>
<option value="Malik">Malik</option>
<option value="Ankit">Ankit</option>
<option value="Vikrant">Vikrant</option>
</select></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>LeadSource</td>
<td><select name="LeadSource">
<option value="None">None</option>
<option value="Advertisement">Advertisement</option>
<option value="ColdCall">ColdCall</option>
<option value="LinkedIn">LinkedIn</option>
<option value="Web">Web</option>
</select></td>
<!--<td><input type="text" name="LeadSource"></td>-->
</div>
<div class="leftside">
<td>First_name</td>
<td><input type="text" name="First_name"></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>Last_name</td>
<td><input type="text" name="Last_name"></td>
<td>AccountName</td>
<td><input type="text" name="AccountName"></td>
</tr>
<tr>
<td>Title</td>
<td><input type="text" name="Title"></td>
<td>EmailID</td>
<td><input type="text" name="EmailID"></td>
</tr>
<tr>
<td>Industry</td>
<td><input type="text" name="Industry"></td>
<td>Department</td>
<td><input type="text" name="Department"></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="Phone" required></td>
<td>Mobile</td>
<td><input type="text" name="Mobile"></td>
</tr>
<tr>
<td>Today_date</td>
<td><input type="date" name="Today_date"></td>
<td>LinkedIn</td>
<td><input type="text" name="LinkedIn"></td>
</tr>
<tr>
<td>CallStatus</td>
<td><select name="CallStatus">
<option value="None">None</option>
<option value="AnsweringMachine">AnsweringMachine</option>
<option value="Callback">Callback</option>
<option value="NotInterested">NotInterested</option>
<option value="Prospect">Prospect</option>
<option value="WrongContact">WrongContact</option>
<option value="PerformedInternally">PerformedInternally</option>
<option value="LessThan30Employee">LessThan30Employee</option>
</select></td>
<td>Website</td>
<td><input type="text" name="Website"></td>
</tr>
</table>
<!-- Second table-->
<table>
<tr><td><b>Address Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>Street</td>
<td><input type="text" name="Street"></td>
</div>
<div class="rightside">
<td>OtherStreet</td>
<td><input type="text" name="OtherStreet"></td>
</div>
</tr>
<tr>
<div class="leftside">
<td>City</td>
<td><input type="text" name="City"></td>
</div>
<div class="rightside">
<td>State</td>
<td><input type="text" name="State"></td>
</div>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" name="Zip"></td>
<td>Country</td>
<td><input type="text" name="Country"></td>
</tr>
</table>
<!--Third table-->
<table>
<tr><td><b>Description Information</b></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="Description" class="Description"></td>
</table>
<button type="button">Cancel</button>
<button type="button" class="button2" onclick="window.location.href='fetch_data.php'" />View</button>
<button type="button" class="button3" onclick="window.location.href='exm_list.php'" />Edit</button>
<button type="submit">Add</button>
</form>
< /body>
</html>
PHP Code:
<?php
// create a variable
if (isset($_POST)){
$ContactID=$_POST['ContactID'];
$ContactOwner=$_POST['ContactOwner'];
$LeadSource=$_POST['LeadSource'];
$First_name=$_POST['First_name'];
$Last_name=$_POST['Last_name'];
$AccountName=$_POST['AccountName'];
$Title=$_POST['Title'];
$EmailID=$_POST['EmailID'];
$Industry=$_POST['Industry'];
$Department=$_POST['Department'];
$Phone=$_POST['Phone'];
$Mobile=$_POST['Mobile'];
$Today_date=$_POST['Today_date'];
$LinkedIn=$_POST['LinkedIn'];
$CallStatus=$_POST['CallStatus'];
$Website=$_POST['Website'];
$Street=$_POST['Street'];
$OtherStreet=$_POST['OtherStreet'];
$City=$_POST['City'];
$State=$_POST['State'];
$Zip=$_POST['Zip'];
$Country=$_POST['Country'];
$Description=$_POST['Description'];
}
//create connection
$connect=mysqli_connect('localhost','root','','contacts');
$check="SELECT COUNT(*) FROM contact where ContactID='$_POST[ContactID]' ";
$result=mysqli_query($connect,$check);
$data=mysqli_fetch_array($result, MYSQLI_NUM);
if($data[0] > 1){
echo "LinkedIn id already exists";
}
else {
$newUser="INSERT INTO contact(ContactID,ContactOwner,LeadSource,First_name,Last_name,AccountName,Title,EmailID,Industry,Department,Phone,Today_date,LinkedIn,CallStatus,Website,Street,OtherStreet,City,State,Zip,Country,Description)
VALUES('$ContactID','$ContactOwner','$LeadSource','$First_name','$Last_name','$AccountName','$Title','$EmailID','$Industry','$Department','$Phone','$Today_date','$LinkedIn','$CallStatus','$Website','$Street','$OtherStreet','$City','$State','$Zip','$Country','$Description')";
if (mysqli_query($connect,$newUser))
{
echo "Information Added<br/>";
}
else
{
echo "Error adding user in database, ContactID exists.<br/>";
}
}
Try changing:
$check="SELECT COUNT(*) FROM contact where ContactID='$_POST[ContactID]' ";
to
$check="SELECT COUNT(*) FROM contact where ContactID='$ContactID' ";
Also:
Form is not saving data if user do not enters ContactID. *** ContactID
is an autoincrement field in mysql table.
In your insert do not include
ContactID,
since this is an autoincrement field as you mention. What you should do instead is to do this:
//create connection
$connect=mysqli_connect('localhost','root','','contacts');
$check="SELECT COUNT(*) FROM contact where ContactID='$ContactID' ";
$result=mysqli_query($connect,$check);
$data=mysqli_fetch_array($result, MYSQLI_NUM);
if($data[0] > 1){
echo "LinkedIn id already exists";
}else {
$newUser="INSERT INTO contact(ContactOwner,LeadSource,First_name,Last_name,AccountName,Title,EmailID,Industry,Department,Phone,Today_date,LinkedIn,CallStatus,Website,Street,OtherStreet,City,State,Zip,Country,Description)
VALUES('$ContactOwner','$LeadSource','$First_name','$Last_name','$AccountName','$Title','$EmailID','$Industry','$Department','$Phone','$Today_date','$LinkedIn','$CallStatus','$Website','$Street','$OtherStreet','$City','$State','$Zip','$Country','$Description')";
if (mysqli_query($connect,$newUser))
{
echo "Information Added<br/>";
}
}

Autocomplete attribute in html form not working

I want to have an update option in my html form in which user enters First_name then all the fields should be autofilled with corresponding values in mysql table.
I tried to use autocomplete attribute in few fields and it is not working.Please check the code and let me know if there is any error.Or any other way to implement the requirement.
<form method="post" action="demo1.php" autocomplete="on">
<link rel="stylesheet" href="contact_css.css">
<!--Create a table -->
<table>
<tr><td><b>Contact Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>ContactID</td>
<td><input type="text" name="ContactID" autocomplete="ContactID"></td>
</div>
<div class="rightside">
<td>ContactOwner</td>
<!-- <td><input type="text" name="ContactOwner"></td>-->
<td><select name="ContactOwner">
<option value="None">None</option>
<option value="Malik">Malik</option>
<option value="Manish">Manish</option>
<option value="Ankit">Ankit</option>
<option value="Vikrant">Vikrant</option>
</select></td>
</div>
<tr>
<div class="rightside">
<td>LeadSource</td>
<td><select name="LeadSource">
<option value="None">None</option>
<option value="Advertisement">Advertisement</option>
<option value="ColdCall">ColdCall</option>
<option value="EmployeeReferral">EmployeeReferral</option>
<option value="ExternalReferral">ExternalReferral</option>
<option value="OnlineStore">OnlineStore</option>
<option value="Partner">Partner</option>
<option value="Web">Web</option>
<option value="TradeShow">TradeShow</option>
</select></td>
<!--<td><input type="text" name="LeadSource"></td>-->
</div>
<div class="leftside">
<td><label for="First_name">First_name</td>
<td><input type="text" id="First_name" name="First_name" autocomplete="First_name"></td>
</div>
</tr>
<tr>
<div class="rightside">
<td>Middle_name</td>
<td><input type="text" name="Middle_name" autocomplete="Middle_name"></td>
</div>
<td>Last_name</td>
<td><input type="text" name="Last_name" autocomplete="Last_name"></td>
</tr>
<tr>
<td>AccountName</td>
<td><input type="text" name="AccountName"></td>
<td>EmailID</td>
<td><input type="text" name="EmailID"></td>
</tr>
<tr>
<td>Department</td>
<td><input type="text" name="Department"></td>
<td>Phone</td>
<td><input type="text" name="Phone"></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="number" name="Mobile"></td>
<td>Fax</td>
<td><input type="number" name="Fax"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="date" name="DOB"></td>
<td>Assistant</td>
<td><input type="text" name="Assistant"></td>
</tr>
<tr>
<td>AsstPhone</td>
<td><input type="number" name="AsstPhone"></td>
<td>ReportsTo</td>
<td><input type="text" name="ReportsTo"></td>
</tr>
<tr>
<td>LinkedIn</td>
<td><input type="text" name="LinkedIn"></td>
<td>CallStatus</td>
<td><select name="CallStatus">
<option value="None">None</option>
<option value="AnsweringMachine">AnsweringMachine</option>
<option value="Callback">Callback</option>
<option value="NotInterested">NotInterested</option>
<option value="Prospect">Prospect</option>
<option value="WrongContact">WrongContact</option>
<option value="PerformedInternally">PerformedInternally</option>
<option value="LessThan30Employee">LessThan30Employee</option>
</select></td>
</tr>
</table>
<!-- Second table-->
<table>
<tr><td><b>Address Information</b></td>
</tr>
<tr>
<div class="leftside">
<td>Street</td>
<td><input type="text" name="Street"></td>
</div>
<div class="rightside">
<td>OtherStreet</td>
<td><input type="text" name="OtherStreet"></td>
</div>
</tr>
<tr>
<div class="leftside">
<td>City</td>
<td><input type="text" name="City"></td>
</div>
<div class="rightside">
<td>State</td>
<td><input type="text" name="State"></td>
</div>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" name="Zip"></td>
<td>Country</td>
<td><input type="text" name="Country"></td>
</tr>
</table>
<!--Third table-->
<table>
<tr><td><b>Description Information</b></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="Description" class="Description"></td>
</table>
<button type="button">Cancel</button>
<!-- <button type="submit">Save and New</button>-->
<button type="submit">Save</button>
</form>
</body>
This is not how autocomplete attribute is working.
Definition and Usage
The autocomplete attribute specifies whether or not an input field
should have autocomplete enabled.
Autocomplete allows the browser to predict the value. When a user
starts to type in a field, the browser should display options to fill
in the field, based on earlier typed values.
Note: The autocomplete attribute works with the following
types: text, search, url, tel, email, password, datepickers, range,
and color.
SYNTAX
<input autocomplete="on|off">
This attribute can have only value on or off
Refer to w3schools docs for more details
If you want to have a default value in those fields you can set it inside value attribute or design your database with DEFAULT values.
So you can change <input type="text" name="ContactID" autocomplete="ContactID"> to <input type="text" name="ContactID" value="ContactID">

php - Inserted data was not saving in phpmyadmin database

I want to save my data in my phpmyadmin database.But it's not saving. So while saving my data, it refresh the page but data not showing in database
Here is my class by which i want to save data:
class User{
public function __construct(){
$host='localhost';
$user='root';
$password='';
$conn=mysql_connect($host,$user,$password);
if(!$conn){
die("Database Not Connected" . mysql_error());
}
mysql_select_db("db_sign_up");
echo "Database created! ";
}
public function save_user($data){
$sql="INSERT INTO tbl_user(first_name,last_name,email_address,password,mobile_number,address,
city_name,country_name,zip_code)
VALUES('$data[first_name]','$data[last_name]','$data[email_address]','$data[password]',
'$data[mobile_number]','$data[address]','$data[city_name]','$datacountry_name]','$data[zip_code]')";
if(!mysql_query($sql)){
die("sl Error". mysql_error());
}
echo "Saved Successfully!";
//mysql_close($conn);
}
}
here is UI
<?php
require_once './classes/user.php';
$obj=new User();
if(isset($_POST['btn'])){
$obj->save_user($_POST);
}
?>
<html>
<head><title> Database Basic</title></head>
<body>
<form action="sign_up.php" method="post">
<table border="1">
<tr><td>Personal Information</td><td></td></tr>
<tr>
<td> First Name</td>
<td>
<input type="name" name="first_name" value="<?php if(isset($_POST['first_number'])){ echo htmlentities($_POST['first_name']);} ?> "/>
</td>
</tr>
<tr>
<td> Last Name</td>
<td>
<input type="name" name="last_name" value="<?php if(isset($_POST['last_name'])){ echo htmlentities($_POST['last_name']);} ?> "/>
</td>
</tr>
<tr>
<td> Email Address</td>
<td>
<input type="name" name="email_address" value="<?php if(isset($_POST['email_address'])){ echo htmlentities($_POST['email_address']);} ?> "/>
</td>
</tr>
<tr>
<td> Password</td>
<td>
<input type="password" name="password" value="<?php if(isset($_POST['password'])){ echo htmlentities($_POST['password']);} ?> "/>
</td>
</tr>
<tr>
<td> Mobile Number</td>
<td>
<input type="name" name="mobile_number" value="<?php if(isset($_POST['mobile_number'])){ echo htmlentities($_POST['mobile_number']);} ?> "/>
</td>
</tr>
<tr>
<td> Address</td>
<td>
<textarea name="address" rows="4" cols="30"></textarea>
</td>
</tr>
<tr>
<td> City</td>
<td>
<input type="" name="city_name" value="<?php if(isset($_POST['city_name'])){ echo htmlentities($_POST['city_name']);} ?> "/>
</td>
</tr>
<tr>
<td> Country</td>
<td>
<select name="country_name">
<option value=" ">Select Country ...</option>
<option value="bangladesh">Bangladesh</option>
<option value="srilanka">Srilanka </option>
<option value="india">India</option>
</select>
</td>
</tr>
<tr>
<td> Zip Code</td>
<td>
<input type="name" name="zip_code" value="<?php if(isset($_POST['zip_code'])){ echo htmlentities($_POST['zip_code']);} ?> "/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="btn" value="Save">
</td>
</tr>
</table>
</form>
</body>
You have an error in your INSERT STATEMENT:
you are using countryname variable in your query as:
'$datacountry_name]'
I think this should be like this:
'$data[country_name]'
Side note:
You are using mysql_ its deprecated I suggest you to use mysqli_ or PDO.
secondly your code is open for SQL Injection, you need to prevent with sql injection.
its function receives an array, then check your array. The type fields in the db, and if are properly filled.
field int type = int value
if it is returned as a string, you can convert this:
$string = $data[mobile_number];
$int = (int)$string; // convert string type for int.
or use the type varchar to the field
if not the case, say more about the your code.

'' is not a valid value for the type xsd:date (PHP)

I have an HTML form that posts all the gathered information (i.e. when the user enters the details and clicks on submit) it will post to the to a PHP script for processing. The problem is that when I do not pass any value for the date fields, I am getting the error below.
Error: '' is not a valid value for the type xsd:date
How can I make my post accept a null value for the fields and successfully submit?
Form.html:
<form class="form-horizontal" action="CandidateCreationPage.php" method="post" enctype="multipart/form-data">
<table class="form-table">
<tbody>
<tr>
<td class="label-cell"><label>First Name <span class="required-input letters-only">*</span></label></td>
<td>
<input class="required-field letters-only" type="text" name="firstname" id="first-name" maxlength="25" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Last Name <span class="required-input">*</span></label></td>
<td>
<input class="required-field letters-only" type="text" name="lastname" id="last-name" maxlength="30" />
</td>
</tr>
<tr>
<td class="label-cell"><label>How Did You Learn of This Opportunity? <span class="required-input">*</span></label></td>
<td>
<select class="required-field" id="hear-this-opportunity" name="hearthisopportunity">
<option value="">--None--</option>
<option value="Kijiji">Kijiji</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>Please Specify (If Applicable) <span id="please-specify-asterisk" class="required-input hide">*</span></label></td>
<td>
<input class="letters-only" type="text" name="pleasespecify" id="please-specify" maxlength="50" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Status</label></td>
<td>
<select id="status" name="status">
<option value="">--None--</option>
<option value="Full-time">Full-time</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>Have You Worked With Us Before?</label></td>
<td>
<select id="worked-previously" name="workedpreviously">
<option value="">--None--</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>
<tr>
<td class="label-cell"><label>When (If Applicable)</label></td>
<td>
<input type="text" name="workedpreviouslywhen" id="worked-previously-when" />
</td>
</tr>
<tr>
<td class="label-cell"><label>Available to Start</label></td>
<td>
<input type="text" name="availabletostart" id="available-to-start" />
</td>
</tr>
<tr>
</form>
</body>
</html>
Post.PHP
if(isset($_POST['submit']))
{
try{
$fields = array (
'First_Name__c' => $_POST['firstname'],
'Last_Name__c' => $_POST['lastname'],
'Primary_contact_number__c'=>$_POST['primarycontactnumber'],
'Secondary_contact_number__c'=>$_POST['secondarycontactnumber'],
'Email__c'=> $_POST['email'],
'How_did_you_learn_of_this_Opportunity__c'=>$_POST['hearthisopportunity'],
'Please_Specify__c'=>$_POST['pleasespecify'],
'Status__c'=>$_POST['status'],
'Have_you_worked_with_us_before__c'=>$_POST['workedpreviously'],
'When__c'=>$_POST['workedpreviouslywhen'],
'Available_to_start__c'=>$_POST['availabletostart'],);
as an alternative way You can remove date related variables from the first array declaration and thereafter You can check if date variables are not empty and append them to your fields array.
$fields = array (
'First_Name__c' => $_POST['firstname'],
'Last_Name__c' => $_POST['lastname'],
etc
}
remove from $fields array variables like:
["When__c"]=>
["Available_to_start__c"]
and then lets check, and append variables to an array if they are not empty:
if(!empty($_POST['When'])){
$fields['When__c'] = $_POST['When'];
}
if(!empty($_POST['AvlToStart'])){
$fields['Available_to_start__c'] = $_POST['AvlToStart'];
}
etc

Check drop down and create if statement based on that selection

I want to create a php variable depending on what was selected in a drop down.
This is the drop down:
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
Depending if "per hour" or "per annum" was selected, I want to do the following (I'm not quite sure syntax wise if this is correct and this part is on another page):
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
How can this be done?
Here's my full form:
<form action="<?php the_permalink(); ?>calculations" method="post">
<h2>Savings calculator</h2>
<div class="calculator-divide"></div>
<table border="0">
<tr>
<td colspan="3"><h3>Current service costs</h3></td>
</tr>
<tr>
<td width="440"><p>Pharmacist</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="22.00" type="text" name="pharmacist" />
</p></td>
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
</tr>
<tr>
<td><p>Dispenser / Technician</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="8.00" type="text" name="dispenser" />
</p></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><h3>Time taken to carry out manual dispensing tasks</h3></td>
</tr>
<tr>
<td><p>Measure 50mls dose by hand including Pharmacist check</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="1" type="text" name="measure-check" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Preparing labels from dispensary system</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="0.5" type="text" name="labels" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Write up CD register</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="2" type="text" name="cd-register" />
Minute(s)</p></td>
</tr>
<tr>
<td></td>
<td colspan="3"><div class="estimate">
<input style="margin-bottom:20px;" type="submit" value="Estimate my savings" />
</div></td>
</tr>
</table>
</form>
<select id="ddlTime" name="ddlTime">
and
if( $_POST['ddlTime']=='perhour' ){
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
}elseif( $_POST['ddlTime']=='perannum' ){
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
}
I hope this help you :
<?php
if(isset ($_POST['save']))
{
$temp = $_POST['opsi'];
echo $temp;
}
?>
<html>
<body>
<form action="newEmptyPHP.php" method="POST">
<h3> Choose Your Option</h3>
<select name="opsi">
<option value=0 selected>- Customer -</option>
<option value="perannum" name="perannum">perannum</option>
<option value="perhour" name="perhour">perhour</option>
</select> <br> <br>
<input type="submit" name="save" value="Save and Commit">
</form>
</body>
</html>

Categories