Hi,

I'm trying to make a login page.

I have an HTML that calls 'register.php' once sumbit button is entered.

Then, 'register.php' check all inputs(via _POST) and returns couple of variables(lets say 'success', 'error_code').

<< quetion starts here >>
Then the HTML reacts depends on these returned variables.
If 'success==1', go to "success.html".
If 'success'==0, reload itself and shows the "error_code".

So, how does 'register.php' return variable to the HTML ?
How do I make HTML to redirect based on these returned variable ?

Thanks !

Jake.

😉

    very simple for example embed <?php ?> or <? ?> tags into your html code so it echos out what you want

    i.e.

    HTML CODE HERE.......

    <?
    if ($variable == 0)
    {
    echo "blah blah blah";
    }
    else if ($variable == 1)
    {
    echo "blah blah blah";
    }
    ?>

    Rest Of HTML CODE HERE.......

    that will print a message whether the login was accepted or not 😉

    (Oh yea but you might need to pass the variables by puting them in a .inc file with the functions that manipulate them so that you can include it in the HTML file so that you can keep it all in one file)

      Thanks for the reply, but not sure if I got the answers.
      I want to know :
      1) In a situation where HTML calls PHP, How do I make this PHP
      code to return values to HTML.
      2) How does this HTML reload itself based on these returned variables ?
      Thanks.
      Jake.

        Sry about that I will get back to you haven't done that in a while but I will look it up l8r

          I appreciate it Tekron, I'll be waiting.

            Here hope this is what you need

            i.e

            <p>You have this <? $var ?> number of cookies</p>

              Originally posted by Tekron-X
              Here hope this is what you need

              i.e

              <p>You have this <? $var ?> number of cookies</p>

              Whilst that would work in IE, it will not work within OPERA or netscape. It should be <? echo $var; ?>.

              Anyway, I'm not totally convinced this is what the original request was about.

              If I understand correctly, you have a registration form , the contents of which you pass through register.php for processing. Register.php then returns variables based upon the form inputs???

              register.php should be the file handling what to do, NOT the html php, so at the top of your register.php file you need to do the data manipulation/checks etc, then based upon the output you then use a header('Location: /success.php'); etc

              To be honest, your register.php file should contain the registration form, that way if a failure occurs you can reload the initial state of the form (echo'ing back the user input values) complete with any error messages. Just drop echo commands in to the form at various points where you would like your messages to appear, but the variable names will have no value UNLESS the form has been submitted, and as such would simply not appear on the first pass.

              HTH

                Whilst that would work in IE, it will not work within OPERA or netscape. It should be <? echo $var; ?>.

                Anyway, I'm not totally convinced this is what the original request was about.

                Umm... excuse me, at which point did PHP become browser dependent? it depends on the server settings and has absolutely nothing to do with the browser.

                Now, to my interpretation of the issue 😉

                << quetion starts here >>
                Then the HTML reacts depends on these returned variables.
                If 'success==1', go to "success.html".
                If 'success'==0, reload itself and shows the "error_code".

                Something like this, perhaps?

                if($success == 1)
                {
                 header('Location: http://mydomain.com/success.html');
                 exit();
                }
                else
                {
                 header('Location: http://mydomain.com/thisScript.php?errorcode='.$errorcode);
                 exit();
                }
                

                Thus the error code could be accessed via $_GET['errorcode'] .
                Remember that in order for that to work, you must ave no output before the header(), unless you use output buffering.

                  Originally posted by zalath

                  Umm... excuse me, at which point did PHP become browser dependent? it depends on the server settings and has absolutely nothing to do with the browser.



                  Well pardon me for breathing, but it had me stumped for a while why all my scripts from my early learning days which used <? $PHP_SELF ?> would function perfectly well in ie but WOULD choke as soon as run in opera. A quick look at the source code showed that whilst ie interpreted the missing script name, OPERA did not. Unless things have changed in later versions of php, when did it become possible to let php decide for you that you wanted to echo a variable without actually telling it to do so?

                  Just drop this into a single php file, upload and call via browser:

                  <?PHP 
                  $var = "me ";
                  ?>
                  <? $var ?>
                  <? $var ?>
                  <? $var ?>
                  <? $var ?>

                  By your reckoning, you should get "me me me me " printed to screen.

                    siwis is right that was suppose to have a echo in it my bad.

                    I was in a hurry b/c I had to leave the house lol.

                    should have been

                    <p>You have this <? echo "$var"; ?> number of cookies</p>

                      Just food for thought, but cant you also just do something like this:

                      <?=$var?>

                      That "should" just echo the $var out. At least I think that is the correct syntax.

                        Hi guys,
                        thanks for the input. The way to reload itself is to use <form method=post action=current php file>. Then read off variables using $_POST in the same php. It works since all variables are not set in the first loop.
                        To redirect, I used header(Location:[url]http://...[/url]); exit;.
                        Thanks !

                        Jake.

                        🙂

                          Originally posted by siwis
                          Well pardon me for breathing, but it had me stumped for a while why all my scripts from my early learning days which used <? $PHP_SELF ?> would function perfectly well in ie but WOULD choke as soon as run in opera. A quick look at the source code showed that whilst ie interpreted the missing script name, OPERA did not. Unless things have changed in later versions of php, when did it become possible to let php decide for you that you wanted to echo a variable without actually telling it to do so?

                          Euhm... <?= is short for <?php echo at least in versions >= 4, so if short opening tags are enabled, that would work.

                          I must admit to having made a mistake myself though 😉 I disregarded the fact that the original posting had <? $var ?> insteadt of <?=$var?>. I'll blame it on my monitor 😉

                          As for the me me me me example - try it with <?= and see. Depends on the server configuration though.

                          Some variables rely on browser sent data, which the browser can naturally modify, but PHP code executes despite the browser. What I'm after is that the way you handle the variables in your PHP code has absolutely nothing to do with the browser. What does, however, is the variables the browser is willing to pass to the script.

                          <rant>
                          It's difficult for me to understand how IE can possibly interpret the <? $var ?> any better than Opera - as IE will never see that code!
                          </end of rant>

                            zalath,

                            If you take a look at my comments, I said that IE would correctly interpret a failed $PHP_SELF call, whereas OPERA and NETSCAPE do not. But this only works in terms of a hyperlink or form action. I agree entirely that any server side code is transparent to any and all browsers, it is simply that IE is a little more forgiving of certain errors than either of its main 2 competitors.

                            Either way we are now arguing about something which has absolutely no relevance in the exception that <? $var ?> would do nothing, upon which we are both agreed any way! Apologies.

                            However I similarly made a cock up instating that IE would interpret <? $var ?>.

                            As for using <? =$var ?>, I guess you could call me an old timer, but I tend to use the full commands cos they have a lesser habit of coming back and biting you on the arse when php gets upgraded etc

                              Agreed. Actually, I very rarely use them myself 🙂

                              When it comes to using $PHP_SELF in form actions, a blank action field (which would result from for example <form action="<? $PHP_SELF ?>">) implies that the script should in effect be reloaded with the relevant variables submitted.

                              You're right 😃 there's no point to argue. Sorry for my hostile-ish approach, I tend to lose perspective every now and then 😉

                              Anyways (to the amused bystanders of this cockfight) my preferred way is <?php echo $var; ?>. As was yours, I gather?

                              Happy coding. Ignore me - I'm just a rude kid who thinks he's got a grasp of the basics 😉

                                Write a Reply...