Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

Solved: Form Action & PHP In Same Page


(!)

MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,625 posts.
THREAD STARTER
 
Join Date: Oct 2006
24-Feb-2007, 03:55 PM #1
Solved: Form Action & PHP In Same Page
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?
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
24-Feb-2007, 04:09 PM #2
If you want the php file, in the same page of the form then just leave action= empty, like so:

Code:
<form action="">
Howelly's Avatar
Howelly Howelly is offline
Computer Specs
Member with 33 posts.
 
Join Date: Sep 2006
Experience: Intermediate
24-Feb-2007, 09:54 PM #3
or

PHP Code:
<?

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

?>
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
24-Feb-2007, 10:46 PM #4
Or all on one line

PHP Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"></form>
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,625 posts.
THREAD STARTER
 
Join Date: Oct 2006
25-Feb-2007, 01:33 AM #5
Quote:
Originally Posted by knight_47
If you want the php file, in the same page of the form then just leave action= empty, like so:

Code:
<form action="">
I tried that before, it didn't work. Did you ever try it?
brendandonhu's Avatar
Member with 14,681 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
25-Feb-2007, 01:42 AM #6
<form action="#">

If you end up using PHP_SELF, be aware there are possible cross-site scripting issues.
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
25-Feb-2007, 02:51 AM #7
Quote:
Originally Posted by brendandonhu
<form action="#">

If you end up using PHP_SELF, be aware there are possible cross-site scripting issues.
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.

Last edited by knight_47; 25-Feb-2007 at 02:57 AM..
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
25-Feb-2007, 02:57 AM #8
Yeah I have action="" in my calculator script and it works just fine too.
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
25-Feb-2007, 02:58 AM #9
yea I think you need method="post" for it to work. Did you have that MMJ?
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
25-Feb-2007, 03:02 AM #10
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
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
25-Feb-2007, 03:13 AM #11
haha yea, i never knew that! Thanks
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
25-Feb-2007, 03:17 AM #12
I first mentioned it months ago in a tutorial I wrote on Xen
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
25-Feb-2007, 03:28 AM #13
Quote:
Originally Posted by namenotfound
I first mentioned it months ago in a tutorial I wrote on Xen
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
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,625 posts.
THREAD STARTER
 
Join Date: Oct 2006
25-Feb-2007, 03:46 AM #14
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑