Inserting results of While loop to sql server

Hello experts, I am using the while loop below to populate a table with results from my sql server database. The while loop does its purpose of populating the table, but what I am attempting to do is pull the data from this php page to another php page where an update query is located.
I believe a better format for my question would be How to assign values to text inputs generated in a while loop
Below I am posting the code I am using to pull the data from php to populate the table, You can see I am populated text inputs(which is working) , but do not know how to assign a name to the text boxes after the first record is echo'd. I will provide an image to try to clear what I am saying up.

<table width="500" border="1" id="myTable">
  <tr>

    <th width="91" height="50"> <div align="center">DATE</div></th>
    <th width="91"> <div align="center">CREW</div></th>
    <th width="91"> <div align="center">SHIFT</div></th>
    <th width="91"> <div align="center">LINE</div></th>
    <th width="20PX"> <div align="center">#</div></th>
    <th width="91"> <div align="center">Light Station</div></th>
    <th width="91"> <div align="center">Packer</div></th>
    <th width="91"> <div align="center">Packer</div></th>
    <th width="91"> <div align="center">Packer</div></th>
    <th width="91"> <div align="center">Packer</div></th>
    <th width="91"> <div align="center">Palletizer</div></th>
    <th width="91"> <div align="center">Reliever</div></th>



  </tr>

<?php
while($result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC))
{
?>
  <tr>
	<td align="center"  height="50" width="120PX" nowrap> <?php if ($result["DATE"]!= NULL ){echo $result["DATE"] ->format("Y-m-d") ;}?></td>
	<td align="center" width="120px" height="50"  nowrap> <?php echo $result["CREW"];?></td>
	<td align="center" width="10px" height="50"  nowrap> <?php echo $result["SHIFT"];?></td>
	<td align="center" width="50px" height="50"  nowrap><INPUT TYPE="TEXT" NAME="LINE" VALUE=" <?php echo $result["LINE"];?>"></td>
	<td align="center" width="20px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="LINE_NUM" VALUE="<?php echo $result["LINE_NUM"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_1" VALUE="<?php echo $result["PERSON_1"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_2" VALUE="<?php echo $result["PERSON_2"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_3" VALUE="<?php echo $result["PERSON_3"];?>"></td>
	<td align="center" width="140px"height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_4" VALUE="<?php echo $result["PERSON_4"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_5" VALUE="<?php echo $result["PERSON_5"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_6" VALUE="<?php echo $result["PERSON_6"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="PERSON_7" VALUE="<?php echo $result["PERSON_7"];?>"></td>





  </tr>

<?php
}
?>

Open in new window

EXPERTEXCHEANGE.PNG
LVL 1
peter OjedaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peos JohnPHPCommented:
You can set the name for the text boxes are array like below, so it will be easy post the value with same name

	<td align="center" width="50px" height="50"  nowrap><INPUT TYPE="TEXT" NAME="LINE[]" VALUE=" <?php echo $result["LINE"];?>"></td>
	<td align="center" width="20px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="LINE_NUM[]" VALUE="<?php echo $result["LINE_NUM"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="ligt_station[]" VALUE="<?php echo $result["PERSON_1"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="paker1[]" VALUE="<?php echo $result["PERSON_2"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="packer2[]" VALUE="<?php echo $result["PERSON_3"];?>"></td>
	<td align="center" width="140px"height="50"  nowrap> <INPUT TYPE="TEXT" NAME="packer3[]" VALUE="<?php echo $result["PERSON_4"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="packer4[]" VALUE="<?php echo $result["PERSON_5"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="palletizer[]" VALUE="<?php echo $result["PERSON_6"];?>"></td>
	<td align="center" width="140px" height="50"  nowrap> <INPUT TYPE="TEXT" NAME="reliever[]" VALUE="<?php echo $result["PERSON_7"];?>"></td>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
If the app is designed correctly, you might have column names that match the name= attributes in the corresponding input controls.  Since $result is an associative array, the keys can be lined up with the name= attributes, and the values would line up, too.
0
peter OjedaAuthor Commented:
Hi Peos I do not fully understand what you are trying to say. Below is the code on the 2nd php page that I planned to use for the update. The values in the Params array are being posted based on text input Name attributes. That is why i need to have a name for the text inputs that are being created in the while loop.

	if( $conn === false ) {
		die( print_r( sqlsrv_errors(), true));
	}

	$sql = "UPDATE CE_MANNING SET 
				DATE= ? ,
				SHIFT= ? ,
                               LINE= ? ,
				#= ? ,
				LIGHT_STATION= ? ,
                               PERSON_1= ? ,
				PERSON_2= ? ,
				PERSON_3= ? ,
                               PERSON_4= ? ,
				PERSON_5= ? ,
				PERSON_6= ? ,
                               PERSON_7= ? 
				WHERE NAME = ? ";
				
	$params = array($_POST["DATE"], $_POST["SHIFT"], $_POST["LINE"],$_POST["#"], $_POST["LIGHT_STATION"], $_POST["PERSON_1"], $_POST["PERSON_2"], $_POST["PERSON_3"], $_POST["PERSON_4"], $_POST["PERSON_5"], $_POST["PERSON_6"], $_POST["PERSON_7"]);
	

	$stmt = sqlsrv_query( $conn, $sql, $params);
	if( $stmt === false ) {
		 die( print_r( sqlsrv_errors(), true));
	}
	else
	{
		echo "Record update successfully";
	}

	sqlsrv_close($conn);
?>

Open in new window

0
peter OjedaAuthor Commented:
Thank you Peos after further research and testing you were right and this is what I needed to do.
0
Peos JohnPHPCommented:
You are welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.