# Solved: Form Action & PHP In Same Page



## MMJ

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 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

If you want the php file, in the same page of the form then just leave action= empty, like so:



Code:


<form action="">


----------



## Howelly

or



PHP:


<?

$fileName = $_SERVER['PHP_SELF'];
print("");

?>


----------



## namenotfound

Or all on one line



PHP:


">


----------



## MMJ

knight_47 said:


> 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

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


----------



## knight_47

brendandonhu said:


> 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.


----------



## namenotfound

Yeah I have action="" in my calculator script and it works just fine too.


----------



## knight_47

yea I think you need method="post" for it to work. Did you have that MMJ?


----------



## namenotfound

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

haha yea, i never knew that! Thanks


----------



## namenotfound

I first mentioned it months ago in a tutorial I wrote on Xen


----------



## knight_47

namenotfound said:


> 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

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


----------

