Using $_POST with Submit button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antoni

    Using $_POST with Submit button

    Hello,

    I wondered if anyone could further advice? In my script I was trying
    allow the user to enter a userid and password, and when the users
    clicks the login button. Pass these values passed to a method
    login_user, and finally display there record.

    I was hoping to display the record on this page. I would appreicate
    some advice if my scrips looks corrects? I unsure about the line
    if(isset($_POST['login'])){?

    Thank you

    <?php
    function login_form(){
    ?>
    <html>
    <head>
    <title></title>
    </head>

    <body>

    <div align="center">
    <form method="post">
    <table border="1">
    <tr>
    <th align="right">E-mail</th>
    <td nowrap>
    <input name="userid" size="25">
    </td>
    </tr>
    <tr>
    <th align="right">P assword</th>
    <td nowrap>
    <input name="password" size="25">
    </td>
    </tr>
    <tr>
    <td align="center">
    <input type="submit" name="login" value="Login">
    </td>
    </tr>
    </table>
    </form>
    <div>
    <?php
    }

    login_form();

    if(isset($_POST['login'])){
    $userid = $_POST["userid"];
    $password = $_POST["password"];
    $userRecord = login_user($use rid, $password);
    displayRecord($ userRecord);

    echo "</body>";
    echo "</html>";
    }
    ?>

    </body>
    </html>
  • steve

    #2
    Re: Using $_POST with Submit button

    "Antoni" wrote:[color=blue]
    > Hello,
    >
    > I wondered if anyone could further advice? In my script I was[/color]
    trying[color=blue]
    > allow the user to enter a userid and password, and when the users
    > clicks the login button. Pass these values passed to a method
    > login_user, and finally display there record.
    >
    > I was hoping to display the record on this page. I would appreicate
    > some advice if my scrips looks corrects? I unsure about the line
    > if(isset($_POST[’login’])){?
    >
    > Thank you
    >
    > <?php
    > function login_form(){
    > ?>
    > <html>
    > <head>
    > <title></title>
    > </head>
    >
    > <body>
    >
    > <div align="center">
    > <form method="post">
    > <table border="1">
    > <tr>
    > <th align="right">E-mail</th>
    > <td nowrap>
    > <input name="userid" size="25">
    > </td>
    > </tr>
    > <tr>
    > <th align="right">P assword</th>
    > <td nowrap>
    > <input name="password" size="25">
    > </td>
    > </tr>
    > <tr>
    > <td align="center">
    > <input type="submit" name="login"[/color]
    value="Login">[color=blue]
    > </td>
    > </tr>
    > </table>
    > </form>
    > <div>
    > <?php
    > }
    >
    > login_form();
    >
    > if(isset($_POST[’login’])){
    > $userid = $_POST["userid"];
    > $password = $_POST["password"];
    > $userRecord = login_user($use rid, $password);
    > displayRecord($ userRecord);
    >
    > echo "</body>";
    > echo "</html>";
    > }
    > ?>
    >
    > </body>
    > </html>[/color]

    I did not go thru the code fully, so I leave that to others to comment
    on.

    (isset($_POST[’login’]))... refers to detecting that the form has been
    submitted. The value of $_POST[’login’] would be set when the submit
    button has been pressed. As your form and your form-processing logic
    are both on the same script, this is the way of detecting when $_POST
    values are present for processing

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-_POST-Su...ict139727.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467354

    Comment

    Working...