Thanks Konrad. I tried it but it didn't solve my problem... do you have an idea why this might be happening? Thanks
[RESOLVED] Help with $PHP_SELF
Hi, this works for me, is this what you want?
<?php
if (is_numeric($_GET['projectid']) && $_GET['projectid'] > 0)
$projectId = $_GET['projectid'];
else
$projectId = $_POST['value'];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="value" value="<?php echo $projectId; ?>"/>
<input type="submit"/>
</form>
Many thanks for the suggestion. I have a similar logic, but tried to adopt elements of yours to see if my problem got fixed. Unfortunately, it didn't.
What happens is that, once I call the page with a GET argument, the POST FORM seems to be resubmitting that argument over and over again (ie: the line "if isset($_GET..." always returns true)...
If you put $SERVER['SCRIPT_NAME'] as your form action, the form should call the script name without any $GET data... Try to debug your script with print_r($_SERVER);
or paste the entire code, please.
Do GET variables appear in the "action" field if you view the generated HTML code?
Thanks a bunch guys:
The print returns (among other things):
[HTTP_REFERER] => http://localhost/myjewellery/project_maintenance.php?ProjectName=B001
PHP_SELF] => /myjewellery/project_maintenance.php [REQUEST_TIME] => 1148032185 [argv] => Array ( [0] => ProjectName=B001 ) [argc] => 1
On the call with GET and on the subsequent calls clicking on the POST submit button.... I am happy to post the code, but it's quite lengthy so I'm trying other alternatives first.
Also, all subsequent calls using POST still show on the browser's URL the get argument.
Maybe a php.ini configuration problem?
I am not sure if this would make any difference, but the page that calls this page with a GET variable is not done with a submit form but with a link in which I kind of hardcode the GET argument like this:
<a href='project_maintenance.php?ProjectName=". $ProjectsArray[$i]["ProjectName"] ."'>
Could this have anything to do with the fact that the GET argument is persisting? If it does, do you have any idea how I can get rid of the ARGUMENTS after the first GET call (is this possible?)
uhm, the code I pasted was called without a submit form (and it works)...
I think its $SESSION['REQUEST_URI'] instead of $SESSION['SCRIPT_NAME'] as per konrad not that it would help you
Guys, this is just so weird.... If I change my POST action to "project_maintenance.php" (ie: the script name) it works OK. Now when I use $SERVER['PHP_SELF'] or $SERVER['SCRIPT_NAME'] it does not work... guess I'll have to do without using a "smart" reference and will just have to hardcode the file name to get around this (?)
I don't know why it didn't work earlier, but my little hack to check if there is a GET argument on the POST action and remove anything after (and including) the first ? has worked when I've tried now again:
if ($pos = strpos($_SERVER['PHP_SELF'], '?')) {
$PAGE = substr($_SERVER['PHP_SELF'], 1, $pos);
}
Thanks for all your help anyways