1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Form Action & PHP In Same Page

Discussion in 'Web Design & Development' started by MMJ, Feb 24, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. MMJ

    MMJ Guest Thread Starter

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    In a form action the php is usually a separate document how could I make it point to the same doc?

    for example:
    http://w3schools.com/php/php_mysql_insert.asp

    I could just say <form action="index.php"> and have the form AND php in index.php but it doesn't seem to be a good way of doing things.

    any ideas?
     
  2. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    If you want the php file, in the same page of the form then just leave action= empty, like so:

    Code:
    <form action="">
     
  3. Howelly

    Howelly

    Joined:
    Sep 22, 2006
    Messages:
    33
    or

    PHP:
    <?

    $fileName $_SERVER['PHP_SELF'];
    print(
    "<form action=\"$fileName\"></form>");

    ?>
     
  4. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    Or all on one line

    PHP:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>"></form>
     
  5. MMJ

    MMJ Guest Thread Starter

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    I tried that before, it didn't work. Did you ever try it?
     
  6. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    <form action="#">

    If you end up using PHP_SELF, be aware there are possible cross-site scripting issues.
     
  7. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    oops, B's probably right, though I thought I used that once and it worked, I have a very short memory span!

    Edit: I just checked the code to one of my earlier scripts, and it does seem to work, I have this:

    Code:
    <form name="calc" method="post" action="">
    you can view it here.

    Did you have the method="post" there?? If not, that might be why.
     
  8. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
  9. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    yea I think you need method="post" for it to work. Did you have that MMJ?
     
  10. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    Btw Knight, on your site. Instead of manually adding all those CSS classes to highlight the code, if you used the highlight_string() PHP function it would be much easier for you ;)
     
  11. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    haha yea, i never knew that! Thanks :p
     
  12. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    I first mentioned it months ago in a tutorial I wrote on Xen :D
     
  13. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    Yea I think I remember, though I never knew that while I was in the beginning stages of my php coding, I was a total noob :p
     
  14. MMJ

    MMJ Guest Thread Starter

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    Thanks Bren. :)

    Yeah, I had that knight but it still wouldn't work. Oh well I probably had something else wrong.

    404: I can't get to your site, but thats no biggie I couldn't get to mine earlier but knight could.

    I guess this is solved. :)

    edit; knight, with a simple bit of js you can make it when you click on the field in simple math v2 number 1 will go away.

    signout of this site than view the source of the top-right sign in field
     
  15. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/546881