Page 1 of 1
PHP vs MySQL vs Forms. HELP ME!!!
Posted: Thu Feb 06, 2003 12:45 am
by moniarde
I don't know if I'm crazy

, but the tutorials I read make what I need to do so much simpler than the way I am doing it. I am trying to post information from a form back into my mysql db - theoretically pretty simple. Here's what I have so far:
Code: Select all
$sql = "INSERT INTO test SET " .
"test_id='4', " .
"test1='{$_POSTї"form_test1"]}', " .
"test2='{$_POSTї"form_test2"]}'";
$result = mysql_query($sql);
:where "form_test1 & 2" are text inputs in the form. This does work, but that's not the point.
Everytime I want to refer to a value posted from the form, I have to use $_POST. But all the tutorials I read tell me I can refer to input as if it were already a variable. Why can't I? Is it something to do with the fact that I am using PHP4, and the tutorials are written for PHP3?
Hrmmm
Posted: Thu Feb 06, 2003 3:13 am
by Caroline
In PHP4, form input name DO be a variable and you can insert it right away
like this
Code: Select all
mysql_query("INSERT INTO test WHERE test_id = 4 VALUES('form_test1','form_test2')");
Check with your host
Or move your site
here
Posted: Thu Feb 06, 2003 8:43 am
by Rob the R
This is actually dependent on the
register_globals directive being set in your PHP environment. It is generally
more secure to keep register_globals off so that you have to refer to the POST, GET, and COOKIE variables from within the array, like you have observed.
If it's really important for you to be able to refer to the variable without using the $_POST array, you'll have to turn the register_globals directive on.
PHP4 vs 3
Posted: Thu Feb 06, 2003 9:39 pm
by moniarde
So is this problem just a matter of the tutorials being written for PHP3, while I'm using PHP4?
Is there another way to globablly state that all form information gathered should automatically be placed into it's own variable according to the name of the form input ie, send all the information to an array in one relatively small piece of code?
Posted: Fri Feb 07, 2003 2:18 am
by twigletmac
The tutorials are written for the fact that before PHP version 4.2, register_globals was on by default - now it is deprecated and in some future release will not exist any more and is currently off by default.
To get all of the information from the $_POST array to be placed in variables of the same name as the form inputs they came from you can simply use
extract():
and then $_POST['formvar1'] can be refered to as $formvar1.
One thing to note - you really should do some validation of the form data - e.g. make sure what should be numbers really are - before putting data into the database otherwise you could have problems with malicious and/or stupid users messing up your data.
Mac