help on my first php form, please

Discussion in 'PHP' started by cru, Jun 27, 2007.

  1. #1
    hi, im new to php. im currently reading a book by Mcgraw-Hill and practricing my codes, i embedded this code in the body of my html:

    <form action="message.php" method="post">
    	Enter your message: <input type="text" name="msg" size="30">
    	<input type="submit" value="Send">
    	</form>
    
    <?
    
    $input = $_POST['msg'];
    
    echo "you said: $input";
    
    ?>
    Code (markup):
    1. the form shows, and allows me to enter the message
    2. my problem is, when i click submit, it shows this error:

    Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    06/28/07 08:34:49
    Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_

    thanks in advance:D
     
    cru, Jun 27, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    In your case page with your code should be named message.php not some_file.html name since you have PHP code.
    I think you are trying to post to an inexistent URL.
     
    gibex, Jun 27, 2007 IP
  3. fordP

    fordP Peon

    Messages:
    548
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to add message.php in the same directory as the form. Message.php should contain the information needed to process the form.
     
    fordP, Jun 27, 2007 IP
  4. softnmore

    softnmore Peon

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It seems that u want to show the same page when u will submit it. So in this case it is not necessary to mention
    action="message.php"
    Code (markup):
    . Just leave it like
    action=""
    Code (markup):
    or
    action="<?php echo $PHP_SELF; ?>"
    Code (markup):
    . This will work.
     
    softnmore, Jun 27, 2007 IP
  5. dannbkk

    dannbkk Well-Known Member

    Messages:
    1,403
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Yes simply just make the form like so?

    <form action="" method="post">
    	Enter your message: <input type="text" name="msg" size="30">
    	<input type="submit" value="Send">
    	</form>
    
    <?
    
    $input = $_POST['msg'];
    
    echo "you said: $input";
    
    ?>
    PHP:
    do you want the form when submitted do anything? like email? or go to database?
     
    dannbkk, Jun 28, 2007 IP
  6. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    if (isset($_POST['submit']))
    {
         $input = (isset($_POST['msg'])) ? $_POST['msg']: '';
         echo "you said: $input";
    }
    ?>
    <form action="" method="post">
        Enter your message: <input type="text" name="msg" size="30">
        <input type="submit" name="submit" value="Send">
        </form>
    
    PHP:
     
    Acecool, Jun 28, 2007 IP
  7. cru

    cru Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    @ acecool, dannbkk,softnmore, fordp and gibex, thank u so much! actually im trying to insert a shoutbox in my dreamweaver site, but i don't know how to start. :(
     
    cru, Jun 28, 2007 IP