Hi,
I am very new to PHP and I am trying to accomplish the following. I have an SQL (not mysql) database called RiskProfile which has a table in it called Risk. I also have an HTML form that a user fills in and using php, it stores the data into the database. After some trial and error it now works fine. What I want to do next is to retrieve a record in the db and display it into an HTML form based on the users Social.
so far I have been able to query the db and get results back as an echo but every attempt to display the results in a form field has failed.
Here is what I have that does the echo and works:
I have two forms on one HTML page
Form 1 (riskupdate)is an SSN field in which the user types what SSN they want to find and when the "Find" button is clicked it calls results.php which echos the info to the screen:
<form name="riskupdate" method="GET" action="results.php">
<p align="left">Find SSN: <input type="text" name="FindSSN" size="9"></p>
<p align="left"><input type="submit" value="Find" name="B3">
<input type="reset" value="Reset" name="B4"></p>
</form>
Form 2 (riskprofile)this is where I would like the database results to be displayed in the proper fields but have no idea how to do it:
<form name="riskprofile" id="riskpro" method="GET" >
<p align="left">First Name: <input type="text" name="FrstName" id="FrstName" size="50" tabindex="1">
</p>
<p align="left">Last Name: <input type="text" name="LstName" size="50" tabindex="2">
</p>
<p align="left">SSN: <input type="text" name="SocialSecNum" id="SocialSecNum" size="9" tabindex="3"> (No
dashes)</p>
</form>
and here is the code from results.php which currently gets the info and just echos it to the screen insted of into the form riskprofile
<?php
if(! ini_get('date.timezone'))
{
date_default_timezone_set('America/New_York');
}
$serverName = "RSBSQL";
$connectionInfo = array( "Database"=>"RiskProfile", "UID"=>"myDBid", "PWD"=>"myDBpassword");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
die( print_r( sqlsrv_errors(), true ));
}
/*Retrieve data.*/
$find = $_GET['FindSSN'];
$sql = "SELECT * FROM Risk WHERE SSN=$find";
$stmt = sqlsrv_query( $conn, $sql);
if($stmt === false)
{
$errors = sqlsrv_errors();
die(print_r($errors, true));
}
else
{
while($rows = sqlsrv_fetch_array($stmt))
{
echo $_GET['SocialSecNum']=$rows['SSN'];
echo $_GET['FrstName']=$rows['FirstName'];
echo $_GET['LstName']=$rows['LastName'];
}
}
sqlsrv_close( $conn);
?>
Any help you could give would be great.