mjsulliv Posted March 25, 2010 Share Posted March 25, 2010 I'm building a front end to a mySQL db. I want to use two different php files for two different users to start the application (e.g. index_1.php and index_2.php). Each of these pages have a button that will call the sam php form-file.Depending on which index file calls it I want it to select a different table from the database. Problem is i can't figure out how to pass the data from the index file to the form-file. I tried setting a element in the $_SESSION and $_SERVERbut that didn't work -- the elements are not there after the form-file begins execution. Any Thoughts or metods for doing this type of thing would be appreciated.--- Mike Link to comment Share on other sites More sharing options...
boen_robot Posted March 25, 2010 Share Posted March 25, 2010 You mean index_1.php and index_2.php contain the forms, and a third file (let's call it index.php) does the actual processing of the two forms? And depending on the form, you need to choose a different DB?If that's the case, I suggest you add a hidden field to the two forms, specifying the targeted database. Of course, do not let this field determine the database "blindly" - check to see if it's one of the databases your script can handle. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 25, 2010 Share Posted March 25, 2010 You can use either POST or GET. Do you have a form on your index pages or just a link to the form file?If you have a form you can just create another input in the form that will get submitted to the form file and just have a different value for it on each index page. Then access it using the superglobal $_POST variable.Or if you just have a link, you can add a query string to the url before loading the page. Then use the $_GET variable to access it. Link to comment Share on other sites More sharing options...
mjsulliv Posted March 25, 2010 Author Share Posted March 25, 2010 Actually the index file is not a form, it just uses a input button "onClick="location.href='...." to call the page w/ the form.--- Mike Link to comment Share on other sites More sharing options...
justsomeguy Posted March 25, 2010 Share Posted March 25, 2010 The session should work fine, if you set a session variable on the index page you should be able to access that on any other page. Other than that, you can just put a variable in the querystring like jkloth mentioned and access it using $_GET. You can also check $_SERVER['HTTP_REFERER'] to find out which page they came from, if the browser passes that. Link to comment Share on other sites More sharing options...
mjsulliv Posted March 25, 2010 Author Share Posted March 25, 2010 When I set brake points at the "$a/b=1" in both files. At $a=1 there is a $_SESSION variable in the super goobals and it is assigned the "table name". However, after the button click has taken me to the brake point on $b=1 in the called file, there is no $_SESSION variable at all shown in the debugger. index_1.php <?php $_SESSION[dbTable] = "tableName"; $a=1; ?> calledFile.php <?php $localTableName = $_SESSION[dbTable]; $b = 1; ?> $_SERVER['HTTP_REFERER'] only seems to have data about the debugger in it: http://localhost/..../?XDEBUG_SESS...netbeans-xdebugAny thoughts?--- Mike Link to comment Share on other sites More sharing options...
justsomeguy Posted March 25, 2010 Share Posted March 25, 2010 the super goobalsThat's my new band name.You have to use session_start any time you want to use the session, are you doing that on the second page? It's expected that the referer will include information about any proxy you're going though, the referer is a header sent by the browser when you click a link, which tells the server which page you were at when you clicked the link. If you're going through a debugging proxy then that's what the referer will be. Link to comment Share on other sites More sharing options...
mjsulliv Posted March 25, 2010 Author Share Posted March 25, 2010 You have to use session_start any time you want to use the session, are you doing that on the second page?Now that you mention it I remember reading something about that; I'll give it a try --- Thanks!That's my new band name.Oh man! You're in the Super Goobals? I've got all your albums! Link to comment Share on other sites More sharing options...
jeffman Posted March 25, 2010 Share Posted March 25, 2010 Everyone knows the Super Goobals sold out after their second album. All good music eventually goes corporate. It's sad, really. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.