need to convert this asp code to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gcapp
Forum Newbie
Posts: 14
Joined: Thu Jun 01, 2006 8:59 am

need to convert this asp code to php

Post 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.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

Code: Select all

$sParent = trim($_REQUEST['Parent']);
if ($sParent == "") {
 $sParent = null;
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: need to convert this asp code to php

Post 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;
?>
gcapp
Forum Newbie
Posts: 14
Joined: Thu Jun 01, 2006 8:59 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply