2 Replies - 6566 Views - Last Post: 31 March 2009 - 05:38 AM

#1 cobalt-rose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 13-October 08

How to get values from drop down list?

Posted 30 March 2009 - 11:53 AM

Hello, I have been searching for a long while on how to get the values from my drop down list and none of the methods that i have seen actually work with my code... :v:

I have read that it is possible only using javascript? but i have also seen people say that it doable with php? i have tried both methods and i still cannot get the values to be entered into my database
(All of the other fields enter except the fields that i have to select using a drop down

Here is my code...

<? 
echo'<br/>
<div>
			<p class="addjob">Add Job Form</p>
			<form class="job_form" name="job_form" action="do_add_job.php" method="POST">
				<table class="data">
					<tr>
						<td>Job Name</td>
						<td>
							<input type="text" id="job_name" name="job_name" size="20"></td>
							<td ALIGN=CENTER>
						
					<tr>
						<td>Company Name</td>
						<td>

						<select name="Select Company Name">'; 
						echo '<option value="">--Select Company Name--</option>'; 
						while($opt = mysql_fetch_array($result)) 
							{ 
						echo '<option value="' . $opt['company_name'] . '"></option>'; 
							} 
						echo'</select> 

						$num
						<td id="fnamev" class="vn"></td>';
							
						
						
						echo'<tr>
						<td>Start Date</td>
						<td>';
						echo'<input type="text" id="start_date" name="start_date" size="10" )></input>

						<a href="java script:NewCssCal(\'start_date\',\'ddmmyyyy\')"> 
						<img src="sample/images/cal.gif" width="16" height="16" alt="Pick a date"></a>';	
						
						echo'</td>
						
						</tr>

						<tr>
						<td>End Date</td>
						<td>
						
						<input type="text" id="end_date" name="end_date" size="10" )></input>

						<a href="java script:NewCssCal(\'end_date\',\'ddmmyyyy\')"> 
						<img src="sample/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
						
						</td>
						</tr>
						
					<tr>
						<td>Contractor for this job</td>
						<td>
							<SELECT id="contractor" name="contractor" >
							<option value="">--Select Contractor--</option>
							<OPTION VALUE=>James</OPTION>
							<OPTION VALUE=>John</OPTION>
							<OPTION VALUE=>Jim</OPTION>
							</SELECT>
						</td>
					</tr>
					
					<tr>
						<td>Contracted Hours</td>
						<td>
							<input type="text" id="contracted_hours" name="contracted_hours" size="5" ></input>
						</td>
					</tr>
					<tr>
						
						<td>Price</td>
						<td>
							<input type="text" id="job_price" name="job_price" size="10" ></input>
						</td>
					</tr>
					
					<tr>
						
						<td>VAT</td>
						<td>
						<input type="text" id="vat" name="vat" size="10" ></input>
						</td>
					</tr>
					
					<tr>
						<td>Status</td>
							<td>
								<SELECT id="job_status" name="job_status">
									<option value="">--Select--</option>
									<OPTION VALUE="ns">Not Started</OPTION>
									<OPTION VALUE="o">Open</OPTION>
									<OPTION VALUE="c">Completed</OPTION>
								</SELECT>
							</td>
					</tr>
					
					<tr>
						<td>Cost of Job</td>
						<td>
							<input type="text" id="job_cost" name="job_cost" size="10" ></input>
						</td>
					</tr>
					
					<tr>
						<td>Job Created By</td>
						<td>
							<SELECT id="created_by" name="created_by">
								<option value="">--Select--</option>
								<OPTION VALUE=>John</OPTION>
								<OPTION VALUE=>Jim</OPTION>
								<OPTION VALUE=>James</OPTION>
							</SELECT>						
						</td>
					</tr>
					
					<tr>
						<td>Notes</td>
						<td>
							<TEXTAREA id="notes" name="notes"  rows=4 size="110")></TEXTAREA>
						</td>
					</tr>
					
					<tr>
						<td>
							<button type="submit1">SUBMIT</button>
							<class="spacer">
						<td>
					</tr>
					
				</table>
				<br/>
			</form>
			</div>
		<html>
		<head>
		<link href="forms_css.css" rel="stylesheet" type="text/css"  />
		</head>
		<body>
		</body>
		</html>';
							
			?>


And my do_add_job.php code

<?

if ((!$_POST[job_name])  || (!$_POST[notes]) )
		{ header( "Location: add_client_form.php");
		exit;
		} 
else {
	
$db_name = "";

$table_name = "job";

$connection = @mysql_connect("localhost", "", "")
	or die(mysql_error());
	
	$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
	
	$sql = "INSERT INTO $table_name
	(job_name, FK_company_id, date_started, date_finished, FK_contractor_id, hours, price, vat, job_status, created_by, cost, notes) 
VALUES ('$_POST[job_name]', '$_POST[company_name]', '$_POST[start_date]','$_POST[end_date]', '$_POST[contractor]', '$_POST[contracted_hours]', '$_POST[job_price]', '$_POST[vat]', '$_POST[job_status]', '$_POST[created_by]', '$_POST[job_cost]', '$_POST[notes]')";
	
	$result = @mysql_query($sql, $connection) or die(mysql_error());
	
	header("Location:adminpage.php");
	exit;
}

?>

<HTML>
<HEAD>
<TITLE>add client</TITLE>
</HEAD>
<BODY>


Any help would be greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: How to get values from drop down list?

#2 cobalt-rose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 13-October 08

Re: How to get values from drop down list?

Posted 30 March 2009 - 12:59 PM

Ok have figured out why i was not getting the values...
What i am trying to get now is for the drop down list for "company name" to be populated with the company names from my database e.g. "SELECT company_name FROM companies"

Any ideas how i would go about doing this?
Was This Post Helpful? 0
  • +
  • -

#3 roudard  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 143
  • Joined: 26-September 05

Re: How to get values from drop down list?

Posted 31 March 2009 - 05:38 AM

View Postcobalt-rose, on 30 Mar, 2009 - 11:59 AM, said:

Ok have figured out why i was not getting the values...
What i am trying to get now is for the drop down list for "company name" to be populated with the company names from my database e.g. "SELECT company_name FROM companies"

Any ideas how i would go about doing this?


hey,

it seems that youare not selecting anything from the db to fill up your pop up menu :
<td>Company Name</td>
						<td>

						<select name="Select Company Name">'; 
						echo '<option value="">--Select Company Name--</option>'; 
						while($opt = mysql_fetch_array($result)) 
							{ 
						echo '<option value="' . $opt['company_name'] . '"></option>'; 
							} 
						echo'</select> 


$result in $opt = mysql_fetch_array($result) doesn't refer to anything - unless it is before what you actually posted.
you need to do pretty much the same that you do in your d_add_job script
connect to the db, write up your query, run it and store the results in $result before reaching the <select> tag

$connection = mysql_connect("localhost", "", "")
	or die(mysql_error());
	
	$db = mysql_select_db($db_name, $connection) or die(mysql_error());
	
	$sql = "SELECT company_name FROM companies";
	
	$result = mysql_query($sql, $connection) or die(mysql_error());



hope this helps ... :]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1