Click here to Skip to main content
15,893,266 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: getting data from files Pin
cjoki16-Oct-09 7:54
cjoki16-Oct-09 7:54 
Questiondatetime.now Pin
Artakazezs12-Oct-09 2:46
Artakazezs12-Oct-09 2:46 
AnswerRe: datetime.now Pin
Luc Pattyn12-Oct-09 2:58
sitebuilderLuc Pattyn12-Oct-09 2:58 
AnswerRe: datetime.now Pin
EliottA12-Oct-09 3:54
EliottA12-Oct-09 3:54 
QuestionLittle help with my php code pls Pin
wartotojas11-Oct-09 2:34
wartotojas11-Oct-09 2:34 
AnswerRe: Little help with my php code pls Pin
fly90411-Oct-09 6:26
fly90411-Oct-09 6:26 
GeneralRe: Little help with my php code pls Pin
wartotojas11-Oct-09 9:54
wartotojas11-Oct-09 9:54 
GeneralRe: Little help with my php code pls Pin
fly90411-Oct-09 10:24
fly90411-Oct-09 10:24 
wartotojas wrote:
I tought it will work instead of echo statment


No, read some documentation: php.net[^] W3Schools[^].


wartotojas wrote:
It is still doesnt work


Ok. Here is a basic example of how you should do it.
<?php
// If the form has been submitted
if ( isset( $_POST[ 'submit' ] )
{
    // Check name and age are set.
    if ( isset( $_POST[ 'name' ] ) && isset( $_POST[ 'age' ] ) )
    {
        if ( strlen( $_POST[ 'name' ] ) > 0 && strlen( $_POST[ 'age' ] ) > 0 )
        {
            // Do more validation with name and age.
            // Do something with name and age.
            
            if ( *something* )
            {
                // Redirect.
                header( 'Location: redirect.php' );

                // Exit the script.
                exit();
            }
            else
                $result = 'Something went wrong!';
        }
        else
            $result = 'You must fill in name AND age.';
    }
    else
        $result = 'Name and age are not set';
}
?>
<html>
<head>
    ...
</head>
<body>

...

<!-- Output the result, if one is set. -->
<?php echo $result; ?>

<form action="" method="post">
    Name: <input type="text" name="name" />
    Age:  <input type="text" name="age" />
    <input type="submit" name="submit" />
</form

...

</body>
</html>

Notice that the form is processed before anything is output, therefore you can redirect.


To redirect to another page use header( 'Location: members.php' );. This can only be used before you have output anything to the browser.

Example:
This will work
header( 'Location: members.php' );
echo 'This won\'t be output as it the page will have been redirected.';

This won't work
echo 'This has been output, therefore headers cannot be set.';
header( 'Location: members.php' );

The exit() function is normally used after a redirect.

If at first you don't succeed, you're not Chuck Norris.

GeneralRe: Little help with my php code pls Pin
cjoki12-Oct-09 6:12
cjoki12-Oct-09 6:12 
GeneralRe: Little help with my php code pls Pin
fly90412-Oct-09 6:54
fly90412-Oct-09 6:54 
GeneralRe: Little help with my php code pls [modified] Pin
cjoki12-Oct-09 7:54
cjoki12-Oct-09 7:54 
GeneralRe: Little help with my php code pls Pin
fly90412-Oct-09 9:01
fly90412-Oct-09 9:01 
GeneralRe: Little help with my php code pls Pin
cjoki12-Oct-09 9:34
cjoki12-Oct-09 9:34 
GeneralRe: Little help with my php code pls Pin
fly90412-Oct-09 10:22
fly90412-Oct-09 10:22 
GeneralRe: Little help with my php code pls [modified] Pin
cjoki12-Oct-09 11:03
cjoki12-Oct-09 11:03 
GeneralRe: Little help with my php code pls Pin
fly90412-Oct-09 11:50
fly90412-Oct-09 11:50 
GeneralRe: Little help with my php code pls Pin
cjoki12-Oct-09 12:20
cjoki12-Oct-09 12:20 
GeneralRe: Little help with my php code pls Pin
fly90412-Oct-09 12:38
fly90412-Oct-09 12:38 
GeneralRe: Little help with my php code pls Pin
cjoki13-Oct-09 5:05
cjoki13-Oct-09 5:05 
Questioninstallation Pin
WilliamSimon8-Oct-09 12:07
WilliamSimon8-Oct-09 12:07 
Questioninstallation Pin
thangvel8-Oct-09 11:54
thangvel8-Oct-09 11:54 
AnswerRe: installation Pin
Richard MacCutchan14-Oct-09 6:07
mveRichard MacCutchan14-Oct-09 6:07 
AnswerRe: installation Pin
Iranian MM7-Sep-11 9:40
Iranian MM7-Sep-11 9:40 
Questiondownload php code Pin
udch7-Oct-09 1:24
udch7-Oct-09 1:24 
AnswerRe: download php code Pin
EliottA7-Oct-09 2:41
EliottA7-Oct-09 2:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.