New here please help....

Hi everyone,
I am newbie.I am learning PHP.I have tried this code...

>
Enter Name :

Enter Age :-




<?
if (isset($_POST['sendit'])) {
echo "Your Name Is :- ".$_POST['tname'];
}
?>

Now the problem is when i refresh the page previous data displayed (your name is : blah blah bla etc.)
i want , when i click the ok button all the previous text box should disappear and only output should be displayed.

is this possible without creating new form for the result ???

it may be a stupid question :-D ... but please be petient with me.

Thanks in advance :-)


Comments

  • : Hi everyone,
    : I am newbie.I am learning PHP.I have tried this code...
    :
    : >
    : Enter Name :
    :
    : Enter Age :-
    :
    :
    :
    :
    : <?
    : if (isset($_POST['sendit'])) {
    : echo "Your Name Is :- ".$_POST['tname'];
    : }
    : ?>
    :
    : Now the problem is when i refresh the page previous data displayed (your name is : blah blah bla etc.)
    : i want , when i click the ok button all the previous text box should disappear and only output should be displayed.
    :
    : is this possible without creating new form for the result ???
    :
    : it may be a stupid question :-D ... but please be petient with me.
    :
    : Thanks in advance :-)
    :
    :
    :




    First of all you need to ECHO this statement:

    >

    so it should be:

    >


    As per ur question try this:


    :
    : <?
    : if (isset($_POST['sendit'])) {
    : echo "Your Name Is :- ".$_POST['tname'];
    : }

    else{
    echo <<eof
    <form method="POST" action=$_SERVER['PHP_SELF']>
    Enter Name :

    Enter Age :-



    eof;
    }

    : ?>



    Also a note.. you can refer to $_POST['tname'] as $tname (most likely)
    You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    [b][blue]Snoochie Boochies[/blue][/b]

  • :
    : First of all you need to ECHO this statement:
    :
    : >
    :
    : so it should be:
    :
    : >
    :
    :
    : As per ur question try this:
    :
    :
    : :
    : : <?
    : : if (isset($_POST['sendit'])) {
    : : echo "Your Name Is :- ".$_POST['tname'];
    : : }
    :
    : else{
    : echo <<eof
    : <form method="POST" action=$_SERVER['PHP_SELF']>
    : Enter Name :
    :
    : Enter Age :-
    :
    :
    :
    : eof;
    : }
    :
    : : ?>
    :
    :
    :
    : Also a note.. you can refer to $_POST['tname'] as $tname (most likely)
    : You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    : [b][blue]Snoochie Boochies[/blue][/b]
    :
    :
    Hi, Thanks alot for you response.You are so nice.
    I tried your prefered code.It's giving error at the line "echo <<eof" like expecting "," or ";".I used the echo statement as you told (in both the form action statement) but still its not working.I tried my best to fix the error but didn't succeed.
    May be i am doing something wrong that i couldn't understand.I'll appreciate if you find out the errors.:)

  • : :
    : : First of all you need to ECHO this statement:
    : :
    : : >
    : :
    : : so it should be:
    : :
    : : >
    : :
    : :
    : : As per ur question try this:
    : :
    : :
    : : :
    : : : <?
    : : : if (isset($_POST['sendit'])) {
    : : : echo "Your Name Is :- ".$_POST['tname'];
    : : : }
    : :
    : : else{
    : : echo <<eof
    : : <form method="POST" action=$_SERVER['PHP_SELF']>
    : : Enter Name :
    : :
    : : Enter Age :-
    : :
    : :
    : :
    : : eof;
    : : }
    : :
    : : : ?>
    : :
    : :
    : :
    : : Also a note.. you can refer to $_POST['tname'] as $tname (most likely)
    : : You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    : : [b][blue]Snoochie Boochies[/blue][/b]
    : :
    : :
    : Hi, Thanks alot for you response.You are so nice.
    : I tried your prefered code.It's giving error at the line "echo <<eof" like expecting "," or ";".I used the echo statement as you told (in both the form action statement) but still its not working.I tried my best to fix the error but didn't succeed.
    : May be i am doing something wrong that i couldn't understand.I'll appreciate if you find out the errors.:)
    :
    :


    OOPS.. you need THREE < symbols.. so it should be:

    echo <<<eof

    eof;

    [b][blue]Snoochie Boochies[/blue][/b]

  • : : :
    : : : First of all you need to ECHO this statement:
    : : :
    : : : >
    : : :
    : : : so it should be:
    : : :
    : : : >
    : : :
    : : :
    : : : As per ur question try this:
    : : :
    : : :
    : : : :
    : : : : <?
    : : : : if (isset($_POST['sendit'])) {
    : : : : echo "Your Name Is :- ".$_POST['tname'];
    : : : : }
    : : :
    : : : else{
    : : : echo <<eof
    : : : <form method="POST" action=$_SERVER['PHP_SELF']>
    : : : Enter Name :
    : : :
    : : : Enter Age :-
    : : :
    : : :
    : : :
    : : : eof;
    : : : }
    : : :
    : : : : ?>
    : : :
    : : :
    : : :
    : : : Also a note.. you can refer to $_POST['tname'] as $tname (most likely)
    : : : You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    : : : [b][blue]Snoochie Boochies[/blue][/b]
    : : :
    : : :
    : : Hi, Thanks alot for you response.You are so nice.
    : : I tried your prefered code.It's giving error at the line "echo >
    Enter Your Name :
    Enter Age :-



    <?
    if (isset($_POST['sendit'])) {
    if (!empty($_POST['tname']) and !empty($_POST['age'])){
    echo "Your Name Is :- ".$_POST['tname'];
    echo "Your age is :- ". $_POST['age'];
    }
    else{
    echo<<<eof ?>
    >
    <? echo "Enter Name : ";?>

    <? echo "Enter Age :- "; ?>



    <? eof;
    }

    ?>

    I tried ISSET() and EMPTY() functions , those are working fine.But this code is not working.. and i have no clue ... why? :-(

  • [b][red]This message was edited by skylar at 2004-8-9 9:4:29[/red][/b][hr]
    Okay, lets just put everything into php tags.. it's MUCH easier that way:



    Enter Your Name :
    Enter Age :-



    eof;
    if (isset($_POST['sendit'])) {
    if (!empty($_POST['tname']) and !empty($_POST['age'])){
    echo "Your Name Is :- ".$_POST['tname'];
    echo "Your age is :- ". $_POST['age'];
    }
    else{
    echo
    Enter Name :

    Enter Age :-



    eof;
    }
    ?>


    I didn't look long at your code but im "guessing" that your problem is with "<? eof;";

    eof; MUST be the first thing on the line. so:
    <?
    eof;
    ?>
    might work.. or maybe im wrong i don't know lol

    try my code and give me a holler if you got any problems :)


    ---

    Also.. "<<<eof" CANNOT have ANYTHING after it.. no space no nothing, just as eof; CANNOT have ANYTHING before it. <? echo<<<eof ?> might be causing some problems because of this.

    Just keep EVERYTHING that requires php WITHING php tags.. it's easier to echo an entire webpage than to add <? ?> wherever they are needed when they are needed more than a couple times..

  • I just copied your code paste it...but still it's showing the following error :
    Parse error: parse error, unexpected T_SL, expecting ',' or ';' in d:program filesapache groupapachehtdocsskylayer.php on line 2

    I tried to fix the error by using ; and , also but didn't effect.i know ; is not needed there....but just to fix it i tried :-(

    : [b][red]This message was edited by skylar at 2004-8-9 9:4:29[/red][/b][hr]
    : Okay, lets just put everything into php tags.. it's MUCH easier that way:
    :
    :
    : <?php
    : echo <<<eof
    : <form method="POST" action=$_SERVER['PHP_SELF']>
    : Enter Your Name :
    : Enter Age :-
    :
    :
    :
    : eof;
    : if (isset($_POST['sendit'])) {
    : if (!empty($_POST['tname']) and !empty($_POST['age'])){
    : echo "Your Name Is :- ".$_POST['tname'];
    : echo "Your age is :- ". $_POST['age'];
    : }
    : else{
    : echo <<<eof
    : <form method="POST" action=$_SERVER['PHP_SELF']>
    : Enter Name :
    :
    : Enter Age :-
    :
    :
    :
    : eof;
    : }
    : ?>
    :
    :
    : I didn't look long at your code but im "guessing" that your problem is with "<? eof;";
    :
    : eof; MUST be the first thing on the line. so:
    : <?
    : eof;
    : ?>
    : might work.. or maybe im wrong i don't know lol
    :
    : try my code and give me a holler if you got any problems :)
    :
    :
    : ---
    :
    : Also.. "<<<eof" CANNOT have ANYTHING after it.. no space no nothing, just as eof; CANNOT have ANYTHING before it. <? echo<<<eof ?> might be causing some problems because of this.
    :
    : Just keep EVERYTHING that requires php WITHING php tags.. it's easier to echo an entire webpage than to add <? ?> wherever they are needed when they are needed more than a couple times..
    :
    :

  • I found the error..

    it's a weird one..

    PHP is having trouble when we use "$_SERVER['PHP_SELF']" inside of our heredoc

    heredoc reference: http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc


    So i removed it.. : http://www.starreign.net/skylayer.php

    Here is the source: http://www.starreign.net/skylayer.txt


    I hope you can learn from it... but if you have anymore problems im here for you :)
    [b][blue]Snoochie Boochies[/blue][/b]

  • [b][red]This message was edited by netgert at 2004-8-18 23:30:17[/red][/b][hr]
    [italic](some irrelevant text)[/italic]
    :
    : Also a note.. you can refer to $_POST['tname'] as [red]$tname[/red] (most likely)
    : You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    : [b][blue]Snoochie Boochies[/blue][/b]
    :
    think again. this is the case only when registerglobals is set to on (or if you import request vars manually) but by default this is OFF (PHP 4.3.x ?)
    the safest, and recommended way is to always use _POST _GET _COOKIE and _SERVER
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]



  • try this:
    : :
    : : <?php
    : : echo <<<eof
    : : <form method="POST" action=[red]{$_SERVER[PHP_SELF]}[/red]>
    : : Enter Your Name :
    : : Enter Age :-
    : :
    : :
    : :
    : : eof;
    : : if (isset($_POST['sendit'])) {
    : : if (!empty($_POST['tname']) and !empty($_POST['age'])){
    : : echo "Your Name Is :- ".$_POST['tname'];
    : : echo "Your age is :- ". $_POST['age'];
    : : }
    : : else{
    : : echo <<<eof
    : : <form method="POST" action=[red]{$_SERVER[PHP_SELF]}[/red]>
    : : Enter Name :
    : :
    : : Enter Age :-
    : :
    : :
    : :
    : : eof;
    : : }
    : : ?>
    : :
    php cant make up where your variable expression ends ($_SERVER is a variable, $_SERVER['PHP_SELF'] is a variable expression - returning the 'PHP_SELF' element from the variable $_SERVER) so you need to help it a little by surrounding the expression with { and } (curly brackets)
    the same goes with any other in-string variable referencing (that echo <<<eof is actually a multiline string, php makers call it "Here document" :-D)
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • : [b][red]This message was edited by netgert at 2004-8-18 23:30:17[/red][/b][hr]
    : [italic](some irrelevant text)[/italic]
    : :
    : : Also a note.. you can refer to $_POST['tname'] as [red]$tname[/red] (most likely)
    : : You only need to use $_POST if you want to varify that the data was sent via POST.. otherwise you should use $tname instead.
    : : [b][blue]Snoochie Boochies[/blue][/b]
    : :
    : think again. this is the case only when registerglobals is set to on (or if you import request vars manually) but by default this is OFF (PHP 4.3.x ?)
    : the safest, and recommended way is to always use _POST _GET _COOKIE and _SERVER
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :
    :

    Ill say it again like netgert said, DONT DEPEND ON REGISTER GLOBALS BEING ON. Dont listen to the person who told you you should just assume its a set variable, that is terrible advice. ALWAYS use super-globals

    In fact, turn register globals off

    in your .htaccess, on its own line add

    [b]php_flag register_globals off[/b]



    Its an enormous security leak, plus typically makes for extremely confusing and buggy code, and is just asking for your code to break or need to be completely rewritten if your host changes settings or you move to a diff host.

    Also, stop using [b]<? ?>[/b] short tags,
    use [b]<?php ?>[/b]

    it takes no time at all to type <?php opposed to just <? and its much more readable too.

    i dont recomend you use this syntax either to echo (which is what it looks like you were prob trying to do)
    [b]<?=$_SERVER['PHP_SELF']?>[/b]

    its a short tag syntax that is bad for portability, to save having to type 7 more characters, just do [b]<?php echo $_SERVER['PHP_SELF']; ?>[/b]

    its much clearer, and almost guaranteed to never break on you in future versions or with other hosts

    this is how i would recomend coding it, absolutely no need to use eof, (which i dont see much use for anyway, plus its slowwww)

    --------------------
    [code]
    <?php

    if (isset($_POST['tname']) && isset($_POST['age'])) {
    if ((!empty($_POST['tname'])) && (!empty($_POST['age']))) {
    echo '<p>Your Name Is :- '.$_POST['tname'].'';
    echo '

    Your age is :- '.$_POST['age'].'

    ';
    }
    } else { ?>

    ">




    <?php } ?>
    [/code]
    ------------------------

    please note there IS a difference between using
    [b]&&[/b]
    or using
    [b]AND[/b]
    in expressions

    most of the time you want to use [b]&&[/b]
    more info is in the manual

    have a nice day

  • You are so full of yourself

    On every host i've ever worked with Register Globals HAS BEEN ON.

    It is NOT a security leak or these dependable hosts WOULD NOT USE THEM.

    If you aren't checking the validity of you're outside variables then that is your fault. You are the fault in you're programming.


    $myvar is much easier to type than $_POST['myvar'] and i would recommend to ANYONE to use it at will.


    Did you even read their post?
    The person NEVER USED "<?=$_SERVER['PHP_SELF']?> " so what are you going on about?


    And your example is FULL of jargen. This person couldn't possibly make sense of:

    if (isset($_POST['tname']) && isset($_POST['age'])) {
    if ((!empty($_POST['tname'])) && (!empty($_POST['age']))) {


    without reading it a lot more than a couple times.

    You don't need empty() evaluateing $_POST['tname'] returns false when empty so using empty is more JARGEN.

    And the difference between && and And are beyond anything this person might require knowledge of.



    "this is how i would recomend coding it, absolutely no need to use eof, (which i dont see much use for anyway, plus its slowwww)"

    Are you kidding me? I'm guessing you don't script much.
    Or you would rather backslash every single quote in a long string.

    [b][blue]Snoochie Boochies[/blue][/b]

  • : You are so full of yourself
    :
    : On every host i've ever worked with Register Globals HAS BEEN ON.
    :
    : It is NOT a security leak or these dependable hosts WOULD NOT USE THEM.
    :
    : If you aren't checking the validity of you're outside variables then that is your fault. You are the fault in you're programming.
    :
    :
    : $myvar is much easier to type than $_POST['myvar'] and i would recommend to ANYONE to use it at will.

    Here YOU are WRONG
    REGISTER_GLOBALS=ON IS A VERY BIG SECURITY LEAK
    Obviously you have no idea about security. Give me some links to your code using register_globals=on and I will show how to exploit it

    Quote from php.net:
    [code]
    When on, register_globals will inject (poison) your scripts will all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn't require variable initialization means writing insecure code is that much easier. It was a difficult decision, but the PHP community decided to disable this directive by default. When on, people use variables yet really don't know for sure where they come from and can only assume. Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this.
    [/code]

    register_globals should never have existed. When you REALLY need it and REALLY want your script to be insecure, use
    bool import_request_variables ( string types [, string prefix])
    Which is much more better than letting PHP import it all to the global namespace (especially without prefixes!)
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • Oh Man Thanks alot.Really i can never understand it.Thanks to make it clear to me.
    Now i got the answer.
    Thanks for spenting your precious time on it.I am highly obliged to you.

    There is one another thing that i got, it's......
    when i enter both name and age , then it displays it on the nextline.(it's fine)

    When i make empty both fileds then it creates the above field in the next row.Same thing happens when i leave age as blank .Plus when i refresh it it always brings the page with the last operation done.(is it suppose to happen)


    Means if it's displaying name and then it'll show them again on refresh.And if the page has two rows of name and age filed then it'll show them on refresh.

    Is there any way so that if I click on refresh button it just bring me the original page.

    Sorry i am taking your too much time :(

    Regards
    Lucky




    : I found the error..
    :
    : it's a weird one..
    :
    : PHP is having trouble when we use "$_SERVER['PHP_SELF']" inside of our heredoc
    :
    : heredoc reference: http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
    :
    :
    : So i removed it.. : http://www.starreign.net/skylayer.php
    :
    : Here is the source: http://www.starreign.net/skylayer.txt
    :
    :
    : I hope you can learn from it... but if you have anymore problems im here for you :)
    : [b][blue]Snoochie Boochies[/blue][/b]
    :
    :

  • Curly braces doesn't help.
    Getting same error, as i posted before.
    though i got the problem srted out. :)
    Thanks foryour concern

    : try this:
    : : :
    : : : <?php
    : : : echo <<<eof
    : : : <form method="POST" action=[red]{$_SERVER[PHP_SELF]}[/red]>
    : : : Enter Your Name :
    : : : Enter Age :-
    : : :
    : : :
    : : :
    : : : eof;
    : : : if (isset($_POST['sendit'])) {
    : : : if (!empty($_POST['tname']) and !empty($_POST['age'])){
    : : : echo "Your Name Is :- ".$_POST['tname'];
    : : : echo "Your age is :- ". $_POST['age'];
    : : : }
    : : : else{
    : : : echo <<<eof
    : : : <form method="POST" action=[red]{$_SERVER[PHP_SELF]}[/red]>
    : : : Enter Name :
    : : :
    : : : Enter Age :-
    : : :
    : : :
    : : :
    : : : eof;
    : : : }
    : : : ?>
    : : :
    : php cant make up where your variable expression ends ($_SERVER is a variable, $_SERVER['PHP_SELF'] is a variable expression - returning the 'PHP_SELF' element from the variable $_SERVER) so you need to help it a little by surrounding the expression with { and } (curly brackets)
    : the same goes with any other in-string variable referencing (that echo <<<eof is actually a multiline string, php makers call it "Here document" :-D)
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories