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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable to another script when using $_SERVER['PHP_SELF']?? 1

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
This is probably a very easy question, but I can't find a solution on the net.
I have a php form which displays patient records and waiting lists. This has been setup with an action of $_SERVER['PHP_SELF'] so that if a user clicks submit the forms contents are redisplayed to them.
My problem is that I would now like to pass a variable in the same form to another script. Is there a way to pass the variable to this other script without losing the benefits of PHP_SELF (my form has approx 90 text boxes, radio buttons, text areas, dropdown lists, etc.)
Any advice or pointers would be much appreciated.
K
 
you could either use sessions - which allows the global $_SESSION var to be available for scripts run within the same session or if the other script is [tt]include('other_script.php');[/tt], the $_POST var is available to it.

test.php
Code:
<?php

if (isset($_POST['button']))
	include "test2.php";
	
?>

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
	<input type="submit" name="button" value="click Me">
</form>

test2.php
Code:
<?php
print_r($_POST);
?>

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Can you explain the flow a bit more as it doesn't seem to make sense.

FORMpage -> Submit -> FORMPage ->....

Are you re-submitting the form to somewhere else? Are you simply needing to a send a value to another script after the fact?

$_SERVER['PHP_SELF'] simply outputs the current scripts file name, whatever you do to populate the records is not dependent on that.

You can point it to another script, and then populate the records in the same fashion.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Hi,
I think I need to explain this more clearly. I have a form which contains a currently selected patient record. It also has buttons to display waiting lists via table echoing.
The echoed table contains a link for each patient. Clicking a link calls my other script with the variable patient number.
The purpose of this script is to redisplay the selected patient record in the calling form (e.g. SELECT * FROM patienttable WHERE [patientNumber]=$patientNumberThatWasClicked, then return the values).
I can currently link to my other script from the form, build and run the sql. But I can't seem to get the values back into the calling form.
Thanks in advance for your help,
K
 
how is your question different to thread434-1667673

and if it is the same issue:

1. why are you not posting in the original thread?
2. what is it that does not work for you in the solution provided in the original thread?

manipulation of patient data in a database seems to me to be a very important activity to get right. given that you (appear to) have limited experience in php might it be better to tell your employer that this is a project that would be better sent externally to an expert? great quality php coding externally is not expensive.
 
Hi jpadie,
Unfortunately this is for an nhs department with an IT budget of zero, I have no choice in the matter. I have already advised my employer that odbc via Access is not the best way to go. I am not a php programmer but do know VBA. So I have been lumbered with this task.
Your 'echo a table of links that build and run dynamic sql' solution works great. But I am unable to get the dynamic sql result values back into the calling form.
Surely this is a different issue requireing a different thread?
Thanks,
K
 
i don't think that it is a different issue. but at least the two threads are now linked if only by the posts.

the way you get the results back in to the same form is simply to echo them.

it may help you to create some dummy html to show us what you are trying to achieve in each different page.

i don't doubt that you code VBA, dealing with a stateless system like php via the web is a different architectural beast. but if you feel that you could solve the problem in VB why not use asp?
 
So your flow is something along the lines of:

PatientListPage(with a form) -> DBScripttoGetRecords - > ?

If what you want is to populate the form in the original PatientListPage with the data obtained from the DBScripttoGetRecords then you have a few choices:

[ol]
[li]You either need to get the data, and store it in a session, and then redirect to your original form and populate it wit the session data.[/li]
[li]Use some ajax to connect to your script, and then use Javascript to populate your form[/li]
[li] Simply have your DBScripttoGetRecords output another form if that is a possibility. [/li]
[li] Include your DBScripttoGetRecords in your original Form page[/li]
[/ol]





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Hi,
Thanks for everyones input in solving this. I ended up going the session route and it works perfectly.
My apologies for the 2 similar threads (I'll remember for next time).
Regarding using asp. This was my original recomendation to my employer but I understand it can only use sql server (money and licencing issues).
Thanks again,
K
 
umm ... no. there is no reason why php and asp cannot co-exist on the same server.
and there is no reason why asp cannot address any odbc supported database, or even attach to a mysql database.
 
Thanks jpadie,
I was told that websites built using asp.net were restricted to using a sql server backend. Is this not correct?
Cheers,
K
P.S. I have never used asp.net. But am quite experienced in usng VBA. So it should be easier to learn asp (than php)
 
i am not an asp.net guru but I would find it astonishing if asp.net could not address the odbc layer in windows (even if native drivers did not exist). so, no: what you are told is not correct.

not to mention the plethora of articles on the web about using mysql with asp.net...

 
I'll have to look into mysql and asp.net. It would certainly make my life easier!
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top