Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate a form from ado sql recordset in php

Status
Not open for further replies.

dekesc

Programmer
Mar 29, 2012
15
US
I have an asp file which uses vbscript to connect, open and use an ADO sqlserver recordset to populate HTML form elements within the asp file. The db has (the column of interest here) entry_Status as a varchar. The asp file does successfully populate the form element with the following code of one of the form elements, as an example:

document.addform.entryStatus.value = "<%= oRS("entry_Status") %>".

Because of the security risk of vbscript for client-side db access, I want to convert the above functionality using php.

I have created a php file that successfully opens and makes an ADO recordset available to use (left in .open state) but I am not having any success in populating the form elements (as I did with vbscript above).

I have tried several different approaches including the <input ...value="<? echo $entryStatus ?>"... </input>.



I am relatively new to php and could really use help in making this conversion to php work. Clearly, I want to do ado db management as server-side code

php file. Thanks for the help. Let me know if I need to add info for more clarification.

code =
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";NetworkLibrary=".$NetworkLibrary.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr); //Open the connection to the database
$entryStatus = '$_POST[entryStatus]';
$query = "SELECT * FROM careMinistry_test WHERE $entryStatus= '$_POST[entry_Status]'";
$rs = $conn->execute($query);
// leave the recordset open as this page redirects back to the asp file that performed a "location.href=..." to this php file.
//$rs->Close();
//$conn->Close();
//$rs = null;
//$conn = null;
$url = " to doman.org/asp file"; // not real url parameters
header("location:$url");
 
these two lines make no sense
Code:
$entryStatus = '$_POST[entryStatus]';

$query = "SELECT * FROM careMinistry_test WHERE $entryStatus= '$_POST[entry_Status]'";

effectively your query will end up saying (literally)
Code:
$query = "SELECT * FROM careMinistry_test WHERE $_POST[entryStatus] = 'somevalue'";

I believe what you meant is this
Code:
$query = "SELECT * FROM careMinistry_test WHERE entry_Status= '$_POST[entry_Status]'";

please ensure that you escape $_POST['entry_Status'] before using it, to protect against SQL injection attacks.

the recordset will not stay open between a call from php and a call from asp. if you want to use columns from the recordset you will need to retrieve them as variables and pass them expressly to the asp script. or better still, just output the html directly from the php script.

also, if you are redirecting from the asp to the php page by using location.href then then the POST args will not be submitted in the redirect and entry_status will be null. Better instead to change the form action from the calling page to point to the php script directly.
 
Sorry for not getting back on this but I have run into computer problems. I will return when that isseu is resolved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top