473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Having a problem bringing contents of a variable from one page to another.

36
Hi

I am writing a php script that contains a bunch of links. Each link when clicked redirects to the same page however where the clicked link once was is now a textfield. The user then types into the text field once the user has entered input the page redirects to itself again this time where the text field was is a link again. The link is wutever the user typed into the previous text field. I am doing this by using $_REQUEST[....] to get wutever the user types in. So far Ive only been able to get one of these to work. The problem I am having is when the user clicks another link after the process is completed the previous process's variable is erased and the default link is outputted. Can someone help me with this problemF? I am posting a piece of my script.

Thanks

[PHP]$outer_link1 = "<a href=\"?Expand=outer_link1\" >outer_link1</a>";
if ($_REQUEST['Expand'] == "outer_link1")
{
$TextField1 = "<input type=text name=outer1 onChange='submit();' ";
echo("<td>$TextField1</td>");



}

else
{

$outer_link1_contents= $_REQUEST['outer1'];

if ($outer_link1_contents)
{
$outer_link1a = "<a href=\"?Expand=outer_link1\" >$outer_link1_contents</a>";
echo("<td>$outer_link1a</td>");

}
else
{
echo("<td>$outer_link1</td>");
}


}

$outer_link2 = "<a href=\"?Expand2=outer_link2\" >outer_link2</a>";



if ($_REQUEST['Expand2'] == "outer_link2")
{
$outer_link1_contents= $_REQUEST['outer1'];
if ($outer_link1_contents)
{
$outer_link1a = "<a href=\"?Expand=outer_link1\" >$outer_link1_contents</a>";
echo("<td>$outer_link1a</td>");


}
else
{
echo("<td>$outer_link1</td>");
}
$TextField2 = "<input type=text name=outer2 onChange='submit();' ";
echo("<td>$TextField2</td>");



}


else
{


$outer_link2_contents= $_GET['outer2'];
if ($outer_link2_contents)
{
$outer_link2a = "<a href=\"?Expand2=outer_link2\" >$outer_link2_contents</a>";
echo("$outer_link2a");
}
else
{
echo("<td>$outer_link2</td>");

}

} [/PHP]
Feb 14 '08 #1
18 1632
nathj
938 Expert 512MB
Hi,

Each time a user clicks a link they get a text box, completing the text box is supposed to change the text of the link. this works but only for one link at a time.

I think this is bacuase when you pist to a page it gets the page definition from the server and unless you change that file then you will always have this problem. what is happening is you are posting a vraibale to the target page and it's using it just fine. then with the second one it';s getting the original page as the file has not been updated.

To do what you want there are a couple of options open to you.

1. A database
Define the page based on a list of links in a table, then when a user makes a change to this the field in the table is updated and the page is redefined using the latest data from the database.

2. AJAX
When the user clicks a link simply display the text box without going to another page, then one ce the text is entered you can display the link again. This would be the same for each link and as it would never go and get the whole page from the server you would get teh desired results.

The deciding factor is really how permanent the change needs to be and should differnt users be able to set these things independantly of one another.

My prefered solution would be a combo of the database and AJAX.

Decide what exactly this system needs to do and for who and then pick a solution. Read up on the technology and post back here with any questions - I'm happy to try to help.

Cheers
nathj
Feb 14 '08 #2
orfiyus
36
Hi,

Each time a user clicks a link they get a text box, completing the text box is supposed to change the text of the link. this works but only for one link at a time.

I think this is bacuase when you pist to a page it gets the page definition from the server and unless you change that file then you will always have this problem. what is happening is you are posting a vraibale to the target page and it's using it just fine. then with the second one it';s getting the original page as the file has not been updated.

To do what you want there are a couple of options open to you.

1. A database
Define the page based on a list of links in a table, then when a user makes a change to this the field in the table is updated and the page is redefined using the latest data from the database.

2. AJAX
When the user clicks a link simply display the text box without going to another page, then one ce the text is entered you can display the link again. This would be the same for each link and as it would never go and get the whole page from the server you would get teh desired results.

The deciding factor is really how permanent the change needs to be and should differnt users be able to set these things independantly of one another.

My prefered solution would be a combo of the database and AJAX.

Decide what exactly this system needs to do and for who and then pick a solution. Read up on the technology and post back here with any questions - I'm happy to try to help.

Cheers
nathj
^^^^^^^^^^^^^^^^^^^^^^
Unfortunatly Im limited in how I can work on this. I dont have direct access to the database. And Im not allowed to create my own tables. So thats out.

As for AJAX...I had this working in javascript. The problem I had with that tho was that php wasnt able to access wutever I put in the javascript textfield. So thats also out.

Is there any other way to do this or am I trying the impossible at this point?
Feb 14 '08 #3
nathj
938 Expert 512MB
^^^^^^^^^^^^^^^^^^^^^^
Unfortunatly Im limited in how I can work on this. I dont have direct access to the database. And Im not allowed to create my own tables. So thats out.

As for AJAX...I had this working in javascript. The problem I had with that tho was that php wasnt able to access wutever I put in the javascript textfield. So thats also out.

Is there any other way to do this or am I trying the impossible at this point?
Okay so those in charge are making life difficult for you. I think though that AJAX can be your solution as the text fields are still just html text fileds. when the link is clicked simply load the text fields then on the submit of the text field call a JS function with the ID of the text field the JS can get the value and using the XMLHTTP Request object it can be passed to php page with the value on the end of the query string to be retreived by $_GET[].

I think this is the best bet you've got.

Cheers
nathj
Feb 14 '08 #4
ronverdonk
4,258 Expert 4TB
I must admit I haven't looked very carefully at the code (since it is not complete), but have you thought of using the $_SESSION array as a way of saving these links?

Ronald
Feb 14 '08 #5
orfiyus
36
I must admit I haven't looked very carefully at the code (since it is not complete), but have you thought of using the $_SESSION array as a way of saving these links?

Ronald
I have no idea how to use SESSION. You got a link?
Feb 14 '08 #6
ronverdonk
4,258 Expert 4TB
The $_SESSION array allows you to exchange data between pages. Works like an associative array. See these tutorials:
http://www.tizag.com/phpT/phpsessions.php
http://msconline.maconstate.edu/tuto...8/php08-01.php
http://www.phpdeveloper.org/news/5704

Ronald
Feb 14 '08 #7
orfiyus
36
okay how do I use a session to retrieve the contents of a text field?

Would this work?

[PHP]

$TextField1 = "<input type=text name=outer1 onChange='submit();' >";

echo("$TextField1");

$_SESSION['outer1'] = $_REQUEST['outer1'];

echo("$_SESSION['outer1'] ");
[/PHP]
Feb 14 '08 #8
orfiyus
36
^^^^^^^^^^^^^^^^

Yea that code piece dont work. The only thing I cant figure out is how to retrieve the user input in the text field and then store it in a session variable.
Feb 14 '08 #9
ronverdonk
4,258 Expert 4TB
^^^^^^^^^^^^^^^^

Yea that code piece dont work. The only thing I cant figure out is how to retrieve the user input in the text field and then store it in a session variable.
When you want to use the $_SESSION array you MUST start the session at the very beginning of your script, like
[php]<?php
session_start();
.. rest of code
[/php]
In your code sample that would be:
[php]
<?php
session_start();
$TextField1 = "<input type=text name=outer1 onChange='submit();' >";

echo("$TextField1");

$_SESSION['outer1'] = $_REQUEST['outer1'];

echo $_SESSION['outer1'];[/php]
Observe that the echo statement has been corrected because the original one would not show any output.

Ronald
Feb 15 '08 #10
orfiyus
36
okay I got the code to work. I still have the same problem that the value in the variable is being erased once I click a different link. Wut else can I do? Is there sumthing Im missing?

[PHP]

/* ########################### UNEXPAND ################################# */


$unexpand = "<a href=\"?Expand=Unexpand\" >Unexpand</a>";
echo("$unexpand");
session_start();
$outer_link1 = "<a href=\"?Expand=outer1\" >-0-</a>";
$TextField1 = "<input type=text name=outer1 onChange='submit();'>";
$_SESSION['outer1_value'] = $_REQUEST['outer1'];

if ($_REQUEST['Expand'] == "outer1")
{
//$textfield1_value = $_GET['outer1']
//value=$textfield1_value

echo("<td>$TextField1</td>");


}
elseif ( ($_REQUEST['Expand'] == "Unexpand")
|| ($_REQUEST['Expand'] !== "Unexpand") || ($_REQUEST['Expand'] !== "outer1"))
{


echo("should be a changed value");
if (!($_SESSION['outer1_value']))
{
$outer_link1 = "<a href=\"?Expand=outer1\" >-0-</a>";
echo("<td>$outer_link1</td>");
}

echo "<td>session value here<a href=\"?Expand=outer1\" >" . $_SESSION['outer1_value'] . "</td></a>";

}

else
{
echo("Do nothing");
}
[/PHP]
Feb 15 '08 #11
ronverdonk
4,258 Expert 4TB
If you have a session_start() at the top of each script, you do the blanking out of the $_SESSION variable yourself.

Ronald
Feb 15 '08 #12
orfiyus
36
If you have a session_start() at the top of each script, you do the blanking out of the $_SESSION variable yourself.

Ronald
where should I put it then?
Feb 15 '08 #13
ronverdonk
4,258 Expert 4TB
where should I put it then?
'
Sorry for my not-too-clear post. What I mean is that, when you correctly issue the session_start() at the top of each script, then no data in that $_SESSION array can be lost between pages.
So a blank entry in the array is your own doing.

Sorry for the misunderstanding.

Ronald
Feb 15 '08 #14
orfiyus
36
'
Sorry for my not-too-clear post. What I mean is that, when you correctly issue the session_start() at the top of each script, then no data in that $_SESSION array can be lost between pages.
So a blank entry in the array is your own doing.

Sorry for the misunderstanding.

Ronald
Its pretty much right at the top of the page. Im putting in the first few lines. Because the previous author of this script is using session variables for various db related processes. Should I destroy his old session before I start my own?
Theres the first few lines of my script
[PHP]
<?php
require("/scenarios/callable.php");
$db_conn = connect_db();
session_start();

.....

[/PHP]
Feb 15 '08 #15
ronverdonk
4,258 Expert 4TB
You can leave the db-related vars in as long as you are sure that the 'require' script does not also start a session. That is why I would put in at the top right after the <?php statement.

Ronald
Feb 15 '08 #16
orfiyus
36
You can leave the db-related vars in as long as you are sure that the 'require' script does not also start a session. That is why I would put in at the top right after the <?php statement.

Ronald
nah that didnt work. Any other suggestions? Cuz I really got no other ideas on wut to do at this point.
Feb 15 '08 #17
orfiyus
36
nah that didnt work. Any other suggestions? Cuz I really got no other ideas on wut to do at this point.
Well I got it to work. Define the value of the session variable like this and add it to the rest of the code from the previous post

[PHP]$_SESSION['outer2_value'] = ($_REQUEST['outer2'])?$_REQUEST['outer2']:$_SESSION['outer2_value']; [/PHP]
Feb 29 '08 #18
ronverdonk
4,258 Expert 4TB
Well I got it to work. Define the value of the session variable like this and add it to the rest of the code from the previous post

[PHP]$_SESSION['outer2_value'] = ($_REQUEST['outer2'])?$_REQUEST['outer2']:$_SESSION['outer2_value']; [/PHP]
Glad you, at last, found it yourself. See you next time.

Ronald
Feb 29 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike | last post by:
I can not figure out what is going on here. I hope somebody can please help!!! I've got an intranet ASP3 application running on a Win2k server. This application requires a login, so the user...
1
by: Dan King | last post by:
At a summary page, I am trying to clean up Session.Contents so the user can go back to the main page and not retain any unnecessary info. I have entered this into my summary page, but it seems to...
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
20
by: Geoff Cox | last post by:
Hello, How do I get the str_questions values into a form?! The following does not work. I have also tried document.write("<input type='hidden' name='slidervalues' value=str_questions>"); ...
2
by: Prince | last post by:
I have a major problem. I have an entire HTML page stored within a string variable. ex. <html><head><title>text</title></head> <body> some data </body> </html>
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
2
by: COHENMARVIN | last post by:
I have a form with a Submit button. The user fills out the form, clicks the submit button, and then the page posts back to itself. Every time the page posts back to itself, the "Page_Load" event...
5
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.