I have this page which has to retrieve the information from a database and display using the list menu object can someone please let me know of how to do it.

The idea is when the name is selected it will retrieve the information relating to that name from the Database to display in the appropriate boxes. The php is given below.

You can scream if i am asking a stupid question. Sorry.

Someone please help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Hr Leave Application Form</title>
	<script language="JavaScript" src="ts_picker.js">
//Script by Denis Gritcyuk: tspicker@yahoo.com
//Submitted to JavaScript Kit (http://javascriptkit.com)
//Visit http://javascriptkit.com for this script
	</script>
</head>

<body>
<?php

$db_host = "localhost";
$db_user = "xxxx";
$db_pwd = "xxxx";
$db_name = "xxxx";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);

?>

<h1>&nbsp;</h1>
<p>  
<?php
if (!isset($_POST['submit'])) {
?>
</p>
<form action="" method="post" name="tstest">  
<h1>Staff Members Particulars</h1>  

<p>Name:<br>
  <label>
  <select name="name" id="name">
    <option>Name 1</option>
    <option>Name 2</option>
  </select>
  </label>
</p>
<p>Staff Number:<br>
	<input name="staffnumber" type="text" id="staffnumber">
</p>
<p>Department:<br>
	<input type="text" name="department" id="department">
</p>
<p>Present Appoinment:  <br>  
	<input type="text" name="presentappointment" id="presentappointment">
</p>
<p>Period of Present Contract<br />
	<input type="Text" name="contract_start" value="">
	<a href="javascript:show_calendar('document.tstest.contract_start', document.tstest.contract_start.value);">
	<img src="cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the contract_start"></a>
	<input type="Text" name="contract_end" value="">
	<a href="javascript:show_calendar('document.tstest.contract_end', document.tstest.contract_end.value);">
	<img src="cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the contract_start"></a><br />
</p>

<p>  <input type="submit" name="submit" value="Submit New Item">    
<input name="reset" type="reset" id="reset2" value="Clear Form"></p>
</form>
<?php
} 
else {
$name = $_POST['name'];
$staffnumber = $_POST['staffnumber'];
$department = $_POST['department'];
$presentappointment = $_POST['presentappointment'];
$contract_start = $_POST['contract_start'];
$contract_end = $_POST['contract_end'];

mysql_query("INSERT INTO `hrformdetailsNew` (name, staffnumber, department, presentappointment, contract_start,contract_end) 

VALUES ('$name', '$staffnumber','$department','$presentappointment','$contract_start','$contract_end')");

echo "Successfully Submitted!";}


?>

</body>
</html>

Have an onchange event for the select box. When the user selects a name, submit the page. $_POST will have the value selected by the user. Then query the table and get the values, print it.

Have an onchange event for the select box. When the user selects a name, submit the page. $_POST will have the value selected by the user. Then query the table and get the values, print it.

Gentlemen i tried this..what you gave me but i am kind of lost trying it for the whole morning..can you please give me the actual code itself...thanks...

I just want to display all other information when the name is selected...that is information like staff number, contract period etc.

I can show you a simple example.

<?php
$name = $_POST['name'];
echo $name;
//query the table with $name and display the data
?>
<html>
<head>
</head>
<body>
<form name="test" method="post" action="selecttest.php">
<select name="name" onchange="javascript: document.test.submit();">
<option value=''>Select one</option>
<option value=1>1</option>
<option value=2>2</option>
</select>
</form>
</body>
</html>

I can show you a simple example.

<?php
$name = $_POST['name'];
echo $name;
//query the table with $name and display the data
?>
<html>
<head>
</head>
<body>
<form name="test" method="post" action="selecttest.php">
<select name="name" onchange="javascript: document.test.submit();">
<option value=''>Select one</option>
<option value=1>1</option>
<option value=2>2</option>
</select>
</form>
</body>
</html>

Dont want to sound like a bain..but can you please give me the actual working code....please...i have gotten to the part where i can display the name but not other information corresponding to the name. thanks a lot.

I don't know what your code does. So, I can't write you the 'actual working code'. You wrote that piece of code, Right ? If yes, then this shouldn't be difficult.

Hi,

I am just a basic user, i managed to get the form to insert data to the mysql table.

Though i can understand what the code does i am not able to write my own to what i want the form to do to display information.

If you copy and paste the above code you will find that its not the work of 'me' genius but something of microsoft word standard for you in php.

No worries...thanks for the help anyways...cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.