How to make it work?
----------insert.html--------------------
<input type=text name="testfield" >
<input type=submit name="submit" value="submit">
in the insert.php
$sql = "insert into testdb values ('', '$_POST[testfield]')";
i'd like to use $testfield instead of $_POST[testfield], so what should i gonna to do?
$_post
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
do not turn register globals on
use a safe extraction function to pull the variables out of the submission. Safe being that it doesn't generate core errors/warnings if a value doesn't exist, and sanitizes the submitted information (hopefully.)
[php_man]extract[/php_man]() can be used if you want to be extremely lazy, however it's not a safe function, entirely.. but that depends on how your code is written..
use a safe extraction function to pull the variables out of the submission. Safe being that it doesn't generate core errors/warnings if a value doesn't exist, and sanitizes the submitted information (hopefully.)
[php_man]extract[/php_man]() can be used if you want to be extremely lazy, however it's not a safe function, entirely.. but that depends on how your code is written..
I recommend doing it the proper way.
It saves hassle and makes your code more portable if you ever change servers.
eg.
It's as simple as that.
(By the way, you should use quotes for arrays since servers set to parse E_ALL will stop script execution and tell you something about an indefined constant.
)
Some helpful research links:
[big_search]php globals post[/big_search]
It saves hassle and makes your code more portable if you ever change servers.
eg.
Code: Select all
<?php
if ( isset ( $_POST['testfield'] ) )
{
$testfield = trim ( $_POST['testfield'] );
} else {
echo "No var? No page!");
exit ();
}
?>(By the way, you should use quotes for arrays since servers set to parse E_ALL will stop script execution and tell you something about an indefined constant.
Some helpful research links:
[big_search]php globals post[/big_search]
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK