Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I have two php files, in the first php file, I have my form. I'm sending employer number to php2 to get the First Name and Last Name from the employee number.

My concern is, I need to print found row columns like First Name and Last Name inside value element (value="") in the php2. Please help me.

Php1
PHP
<form action="<?php $_PHP_SELF ?>" method="post">
<input type="text" name="firstName" class="password" placeholder="First Name" value=<?php if (isset($_POST['search'])){	$fillEmpNumCombo = $_POST['fillEmpNumCombo'];$data = $db->findEmployee($fillEmpNumCombo); echo $id = $data[0];}?>>;
<input type="text" name="lastName" class="password" placeholder="Last Name" value=<?php if (isset($_POST['search'])){	$fillEmpNumCombo = $_POST['fillEmpNumCombo'];$data = $db->findEmployee($fillEmpNumCombo); echo $id = $data[1];}?>>;


Php2 (db class)
PHP
function findEmployee($fillEmpNumCombo){
$result = mysql_query( "SELECT * FROM Pay_Employee WHERE EmployeeNo='$fillEmpNumCombo'" );
while( $row = mysql_fetch_array( $result ) ) {

return array($row[0], $row[1]);
}
Posted
Updated 8-Sep-14 22:59pm
v3
Comments
ChauhanAjay 8-Sep-14 21:07pm    
Please follow the steps below.

1. Make your function return an array with fistname in 0th index and the lastname in the 1st index.
2. Take the value of the array in the php1 file and set the value of 0th index to the firstname textbox and 1st index to the lastname text box.

for example:
Consider the array $arr[0] = "a" and $arr[1]="b" then you will need to
<input type="text" name="firstName" class="password" placeholder="First Name" value="">
<input type="text" name="lastName" class="password" placeholder="Last Name" value="">

Hope the above solution helps.
abdulsafran 9-Sep-14 4:28am    
Dear ChaunhanAjay, Thanks for the reply. I have modified the code above, please refer. As you mentioned, I have changed the coding to return as return $row[0]; and return $row[1]; in the PHP1 file, but when I'm calling $row[1]; inside the value, it's always getting $row[0]; result. Please help me, I think small modification is needed. Thanks!
ChauhanAjay 9-Sep-14 4:43am    
You will need to return the whole array and not $row[0] or $row[1]. Just return $row.
abdulsafran 9-Sep-14 5:01am    
Dear ChaunhanAjay, Thank you for the reply, I have changed the code accordingly. Now I'm getting small problem, in my database for example: First Name available as Adam John, but when I'm printing to the textbox it is printing as only Adam (the John is missing). Please help me Sir!
ChauhanAjay 9-Sep-14 5:08am    
Change the function like this.
function findEmployee($fillEmpNumCombo){
$result = mysql_query( "SELECT firstname, lastname FROM Pay_Employee WHERE EmployeeNo='$fillEmpNumCombo'" );
$row = mysql_fetch_array($result);
return $row;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900