Page 1 of 1

PHP files involving 'submit' not working in XAMPP

PostPosted: 20. April 2007 06:07
by redzucan
Hye. I'm a newbie here. Im using XAMPP 1.6 for Windows. And currently I've been facing problems with my php code which isnt working while using XAMPP. I've tried using other webservers and the code does work. The problem is that when the php involves 'submit' button, it seems that it does not execute nor does it writes in the database.

I tried browsing through the forum to find similar problems. Perhaps one of the best solutions that I found is as below.


DocBoje wrote:Ah, I've figured it out. Apparently my school has the register_globals = on, so that's why my code was working on their server and not locally.


The question is, how do you register_globals = on ? Or is there some other things that is going wrong. I have checked that all my php codes are using <?php instead of <?.

Kindly please help me. Cheers :)

PostPosted: 20. April 2007 08:46
by Wiedmann
The question is, how do you register_globals = on ?

If this is your problem, you should correct your code and not change this setting....

BTW:
This setting can be changed in the "php.ini".

BTW:
Please read the PHP manual about how to use external variables.

PostPosted: 22. April 2007 22:17
by redzucan
Unfortunately the problem has not been solved. Have been changing "register_globals = on", I still don't understand on the use of external variables and why it is labelled as 'incorrect' as a programming way. I'm not very good in understanding terms but as far as what I have seen and done, I do not see what makes the system not fully working in xampp.

PostPosted: 22. April 2007 23:43
by Wiedmann
I still don't understand on the use of external variables

That's really easy:
if you have this form (method="get") element
Code: Select all
<input type="text" name="test">

or this URI:
Code: Select all
http://localhost/file.php?test=xxx


you can acces this in PHP with:
Code: Select all
$_GET['test']


In a form with method="post" it is:
Code: Select all
$_POST['test']

PostPosted: 30. April 2007 00:03
by ldivinag
ditto if you use a POST method:

Code: Select all
$var = $_POST["form_element"];

PostPosted: 01. May 2007 08:42
by DocBoje
First off, could you post the code that you're having trouble with?

Secondly, if what you're trying to do is pass data from a form to another page that is called from the submit button, and register_globals is OFF on your server (which I believe is default), then you need to call your form variables in a different manner. You need to import the variables from that form using the function "import_request_variables(string $types [, string $prefix]);". Basically, 'string $types' will be a letter (g, p, or c) specifying what method you used to send your data (get, post, or a cookie). The prefix specifies a prefix that will be appended to the beginning of the variable name. When I had this problem, I put this line at the top of my php code:
Code: Select all
import_request_variables("p", "form_");


Then, when I referred to my variables, I referred to them as the variable name in the form with 'form_' in front of it. So if I had a variable called 'txtName' in my form, I would refer to it as 'form_txtName' in my php code.

Hope that helps!

DocBoje

PostPosted: 01. May 2007 14:14
by Dave_L
import_request_variables is a solution, but is also a security risk.

It's better to use $_GET or $_POST as described in the previous posts. Then you know exactly which variables you're accessing.