Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New here please help....

lucky_melucky_me Posts: 39Member
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 :-)


«1

Comments

  • skylarskylar Posts: 82Member
    : 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]

  • lucky_melucky_me Posts: 39Member
    :
    : 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.:)

  • skylarskylar Posts: 82Member
    : :
    : : 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]

  • lucky_melucky_me Posts: 39Member
    : : :
    : : : 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? :-(

  • skylarskylar Posts: 82Member
    [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..

  • lucky_melucky_me Posts: 39Member
    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..
    :
    :

  • skylarskylar Posts: 82Member
    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]

  • netgertnetgert Posts: 331Member
    [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]



  • netgertnetgert Posts: 331Member
    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]

  • rehfeld.usrehfeld.us Posts: 1Member
    : [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

«1
Sign In or Register to comment.