How i can read just one variable from posting?

Discussion in 'PHP' started by Kyriakos, Apr 10, 2008.

  1. #1
    Hi everyone,

    I have a blog (wordpress) but i want to create a independet php page. I want to post 1 variable from a form and to read this variable in my page after posting. i have created this in ASP:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <%
    myvar = request.form("myvar")
    %>
    </head>
    <body>
    <form action="mypage.asp" method="post">
    <input type="text" name="myvar"/>
    <input type="submit" value="Submit"/>
    </form>
    <table>
      <tr>
        <td><%=myvar%></td>
      </tr>
    </table>
    </body>
    </html>
    HTML:
    can anyone convert this in php?

    thanks in advance!
     
    Kyriakos, Apr 10, 2008 IP
  2. sunnyverma1984

    sunnyverma1984 Well-Known Member

    Messages:
    342
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?php
    $myvar = $_post["myvar"];
    ?>
    </head>
    <body>
    <form action="mypage.asp" method="post">
    <input type="text" name="myvar"/>
    <input type="submit" value="Submit"/>
    </form>
    <table>
      <tr>
        <td><?php echo $myvar; ?></td>
      </tr>
    </table>
    </body>
    </html>
    PHP:
     
    sunnyverma1984, Apr 10, 2008 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    it dosn't working. when i type a word in asp page with the code above, this word it's appears inside the table (instead of asp code). but in php it dosn't working. why? i have the wamp server version 2.0 installed.
     
    Kyriakos, Apr 10, 2008 IP
  4. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    i did this correction and it's working now:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?php
    $myvar = Trim(stripslashes($_POST['myvar'])); 
    ?>
    </head>
    <body>
    <form action="mypage.asp" method="post">
    <input type="text" name="myvar"/>
    <input type="submit" value="Submit"/>
    </form>
    <table>
      <tr>
        <td><?php echo $myvar; ?></td>
      </tr>
    </table>
    </body>
    </html>
    HTML:
     
    Kyriakos, Apr 10, 2008 IP
  5. Cobnut

    Cobnut Peon

    Messages:
    184
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It didn't work because $_post is not $_POST, PHP variables are case sensitive.

    Jon
     
    Cobnut, Apr 10, 2008 IP