Jump to content

[SOLVED] Getting data to form


june_c21

Recommended Posts

<?php

#check to see if the submit button has been pressed.
if (isset($_POST['submit'])) {
#if so then output staff number is ... then the value of the textbox sent via post variable
echo "Your stff number is..." . $_POST['staff_no'];

} else {
#if the submit button hasn't been pressed then display the form for the user
echo "<form name=\"Form1\" method=\"POST\" action=$_SERVER['PHP_SELF']>
Staff Number: <input type=text name=staff_no><br>
<input type=submit name=submit value=submit>
</form>";

}

?>

use mysql to query your database where stuff_no = employees_name

 

then create a hidden field in your form and just echo the variable out for your employees name.

 

something like:

 

<?php

// connect to db
// select db
$mystaff = $_POST['staff_no'];
$results = mysql_query("select employee_name from tblName where staff_no='$mystaff'");

while ($mychoice=mysql_fetch_array($results)) {

$employee=$mychoice["employee_name"];

echo "<form name=\"Form1\" action=\"". $_SERVER['PHP_SELF'] ."\">
Staff Number: <input type=text name=staff_no><br>
<input type=\"hidden\" value=\"$employee\" name=\"currentemployee\">
<input type=submit name=submit value=submit>
</form>";

}

?>

well you have to have the employee enter the number some how - if your not using a form for them to enter their employee number in; then how are they entering it?

 

what i want is when user enter their staff no

 

if your using a link with each employees name in them and a predefine employee number in the link; the just change $_POST to $_GET.

 

$mystaff = $_POST['staff_no'];

 

Link To Employee Form

<a href="employeeform.php?staff_no=123">John Doe</a>

I think if im correct you mean that you want it so when ever they type their staff number in

 

 

54 for example it will display the name of that staff member before they press the button. This would need abit of javascript as it is classed as clientside, unless u used abit of ajax.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.