Forums

PHP

This topic is locked

JSP - PHP syntax help

Posted 08 Jan 2002 22:24:31
1
has voted
08 Jan 2002 22:24:31 matt harris posted:
I have a recordset called rsClients and a database with various table relationships and the correct line for one of the session variables I want to store the recordset data to, in JSP is :


session.setAttribute("sclient", rsClients.getObject("CLIENT_NAME");


I'm having trouble however finding the right syntax for PHP - I figure its a "session_register" but what replaces the GetObject command ?

thanks..matt



Replies

Replied 10 Jan 2002 02:19:27
10 Jan 2002 02:19:27 Tim Green replied:
Matt,

Working with Sessions in PHP couldn't be easier <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

To properly set up the session include this at the very top of your page (ensure there are no blank spaces before this block, otherwise you'll get errors):-

&lt;?php
session_start();
if (!session_is_registered("sclient") {
session_register("sclient";
}
?&gt;

Then, later in the page you can easily set the value of the session variable by just using the following:-

&lt;?php
$sclient = $rsClients-&gt;Fields("CLIENT_NAME";
?&gt;

Hope this helps...

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 11 Jan 2002 01:18:48
11 Jan 2002 01:18:48 matt harris replied:
Okay , I think that helps although i'm trying to figure this out through about 4 different tutorials some in asp and some in jsp so i'm getting confused.

1 last shot -

what would this translate as (its asp):

&lt;%session ("MM_Username" = rsLogin.Fields.Item("tfCustomerID".value%&gt;

I've got the PHP blackbook but its like trying to decipher the enigma machine..

thanks again..

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Matt,

Working with Sessions in PHP couldn't be easier <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

To properly set up the session include this at the very top of your page (ensure there are no blank spaces before this block, otherwise you'll get errors):-

&lt;?php
session_start();
if (!session_is_registered("sclient") {
session_register("sclient";
}
?&gt;

Then, later in the page you can easily set the value of the session variable by just using the following:-

&lt;?php
$sclient = $rsClients-&gt;Fields("CLIENT_NAME";
?&gt;

Hope this helps...

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Replied 11 Jan 2002 17:28:49
11 Jan 2002 17:28:49 Tim Green replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
&lt;%session ("MM_Username" = rsLogin.Fields.Item("tfCustomerID".value%&gt;
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

This would directly translate to:-

&lt;?php
$MM_Username = $rsLogin-&gt;Fields("tfCustomerID";
?&gt;

If this was the only session variable on the page you would need to put this at the top of the page:-

&lt;?php
session_start();
if (!session_is_registered("MM_Username") {
session_register("MM_Username";
}
?&gt;

If you were to use it in combination with the previous code posted, then the code block at the begining of the page would be:-

&lt;?php
session_start();
if (!session_is_registered("sclient") {
session_register("sclient";
}
if (!session_is_registered("MM_Username") {
session_register("MM_Username ";
}
?&gt;

Of course, always remember that no HTML or blank spaces should appear above this code block.

Hope this helps.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 12 Jan 2002 18:02:39
12 Jan 2002 18:02:39 matt harris replied:
Okay this is driving me nuts. I'm so close yet so far (I have a hard time getting my head around programming) .

sitrep:

1. I have a form that logs in the user with a user name text field(tfUser)and password textfield (tfPass).

The user logs in and using the "show or hide region if recordset is empty or not empty" server behaviour the log in works fine , I can drag a table field name to the page and it shows up i.e "welcome Tim you have logged in okay".

Then there is a link to the main page where I want to transfer the user to and keep their details registered in a session variable, they then have another greeting and the choice to click on different sections i.e reports , payment etc.

these sections reference different tables connected by the initial user identity established in the log in table.

PROBLEM is that after the initial log in and greeting I can't seem to get the variable to carry across to the next page . This is the greeting page code, i'd greatly appreciate it if you could have a look and am more than happy to send a case of beer in appreciation..

I'm at that point where I'll either get it or give up....

I'm determined to crack this...

&lt;?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../../adodb/adodb.inc.php";
require("./../../Connections/php_conn.php";
?&gt;&lt;?php
$rsLogin__MM_Username = "sdfg";
if (isset($HTTP_POST_VARS["tfUser"]))
{$rsLogin__MM_Username = $HTTP_POST_VARS["tfUser"];}
?&gt;&lt;?php
$rsLogin__MM_Password = "fsg";
if (isset($HTTP_POST_VARS["tfPass"]))
{$rsLogin__MM_Password = $HTTP_POST_VARS["tfPass"];}
?&gt;&lt;?php
$rsLogin=$php_conn-&gt;Execute("SELECT * FROM tbClients WHERE CLIENT_NAME = '" . ($rsLogin__MM_Username) . "' AND CLIENT_PASS = '" . ($rsLogin__MM_Password) . "'" or DIE($php_conn-&gt;ErrorMsg());
$rsLogin_numRows=0;
$rsLogin__totalRows=$rsLogin-&gt;RecordCount();
?&gt;&lt;?php $MM_paramName = ""; ?&gt;&lt;?php
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "" $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";

// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepURL .= "&".$key."=".urlencode($val);
}
}

// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepForm .= "&".$key."=".urlencode($val);
}
}
}

// create the Form + URL string and remove the intial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) &gt; 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) &gt; 0) $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) &gt; 0) $MM_keepForm = substr($MM_keepForm, 1);
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;main menu&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;link rel="stylesheet" href="../../style.css" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#000000" text="#FFFFFF" link="#FF9900" vlink="#0099FF"&gt;
&lt;table width="96%" border="1" cellspacing="0" cellpadding="0" name="tbContainer" align="center"&gt;
&lt;tr&gt;
&lt;td width="4%" valign="top" height="101"&gt;
&lt;div align="left"&gt;&lt;img src="../../images/wiseF.gif" width="42" height="140"&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td height="101"&gt;
&lt;div align="center" class="date"&gt;
&lt;table width="420" border="0" cellspacing="0" cellpadding="10" height="37"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div align="center"&gt;
&lt;?php if ($rsLogin__totalRows&gt;0) { ?&gt;
&lt;font color="#FF9900"&gt;&lt;b&gt;Hello
&lt;?php echo $rsLogin-&gt;Fields("CLIENT_NAME"?&gt;
you have successfully logged in&lt;br&gt;
to the Wisefox Clients site please &lt;a href="menu.php?&lt;?php echo $MM_keepNone.(($MM_keepNone!=""?"&":""."CLIENT_ID=".$rsLogin-&gt;Fields("CLIENT_ID" ?&gt;"&gt;click
here to continue&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;
&lt;?php } // end $rsLogin__totalRows&gt;0 ?&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div align="center"&gt;
&lt;?php if ($rsLogin-&gt;RecordCount()==0) { ?&gt;
&lt;font color="#FF9900"&gt;&lt;b&gt;Sorry you have failed to log in please
try again&lt;/b&gt;&lt;/font&gt;
&lt;?php } // end $rsLogin-&gt;RecordCount()==0 ?&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div align="center"&gt;&lt;font color="#FF9900"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;div align="center"&gt; &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
$rsLogin-&gt;Close();
?&gt;


Replied 13 Jan 2002 16:47:31
13 Jan 2002 16:47:31 Tim Green replied:
When using Session variables you need to put the code block at the beginning of the page, on each and every page that uses the session.

So, your greeting page needs to have:-

&lt;?php
session_start();
if (!session_is_registered("MM_Username") {
session_register("MM_Username";
}
?&gt;

at the very beginning of the page. If it isn't there, then you can't access the values stored in the session. Just replace 'MM_Username' for whatever name you have used for the session...

Hope this helps...

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic