Page 1 of 1
need to convert this asp code to php
Posted: Thu Jun 01, 2006 1:31 pm
by gcapp
Hello,
Can someone help me convert this asp code to php??
sParent = Trim(Request("Parent"))
If sParent = "" Then sParent = Null
I think the only part I'm having an issue with is the Request part.
This is what I have come up with so far and i get an error with the Request part
Code: Select all
$sParent = $temp=Trim(Request('Parent'));
If ($sParent == "") {
$sParent = Null;
}
Any help would be appreciated.
Posted: Thu Jun 01, 2006 2:04 pm
by wtf
Code: Select all
$sParent = trim($_REQUEST['Parent']);
if ($sParent == "") {
$sParent = null;
}
Re: need to convert this asp code to php
Posted: Thu Jun 01, 2006 2:12 pm
by RobertGonzalez
gcapp wrote:Hello,
Can someone help me convert this asp code to php??
sParent = Trim(Request("Parent"))
If sParent = "" Then sParent = Null
I think the only part I'm having an issue with is the Request part.
This is what I have come up with so far and i get an error with the Request part
Code: Select all
$sParent = $temp=Trim(Request('Parent'));
If ($sParent == "") {
$sParent = Null;
}
Any help would be appreciated.
Do you know if the Request object is Request.QueryString or Request.Forms? It's just that I am a stickler for using $_POST and $_GET whenever I can instead of the $_REQUEST superglobal.
Code: Select all
<?php
$sParent = trim($_GET["Parent"]); // Or $_POST["Parent"]
if (empty($sParent)) $sParent = false;
?>
Posted: Fri Jun 02, 2006 7:23 am
by gcapp
Everah,
The php code that I need fixed is based from this asp code:
sParent = Trim(Request("Parent"))
If sParent = "" Then sParent = Null
this code is requesting the field "Parent" from one of the tables in my Access database. So I guess it would be a Request.QueryString. That means it is a $_GET correct?
So what would be the correct coding??
Thanks
Posted: Fri Jun 02, 2006 10:28 am
by RobertGonzalez
gcapp wrote:this code is requesting the field "Parent" from one of the tables in my Access database. So I guess it would be a Request.QueryString. That means it is a $_GET correct?
No, $_GET is a value passed from the querystring (attached to the URL) like this...
http://www.somesite.com?user=fred&age=2 ... status=fat
In this example, the superglobal $_GET array would contain the following values
Code: Select all
$_GET = array(
['user'] => 'fred',
['age'] => 29,
['iq'] => 4,
['status'] => 'fat'
);
If you are pulling information from a database (which it does not look like you ASP code is doing), you would typically be inside of a recordset object...
Code: Select all
<%
' Database connection object
Set cn = Server.CreateObject("ADODB.Connection")
' Database connection string
strConn = "ENTER CONNECTION STRING DETAILS HERE"
' Database connection parameters
strLogin = ""
strPassword = ""
' Connect
cn.open strConn, strLogin, strPassword
' Write a query
sql = "ENTER SOME SQL STATEMENT HERE"
' Open the result the query
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseServer
rs.Open sql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
' You could also use execute
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Execute sql, cn
%>
This is what your typical connection and query execution might look like in ASP. The code you gave looks like it is taking something from the URL and assigning it to a variable for use in the query later. Please confirm.