November 7th, 1999, 01:59 PM
Can anyone please give me some code to tgake input from a html form and post it into my database.
November 7th, 1999, 02:20 PM
This is basicly done like this:
The form sends it values like this to the action url:
This would be if the textinputs in your html form where name and country.
In php you can get the so called query string (the part after the ?) into a variable using this syntax:
$query = getenv("QUERY_STRING");
now $query will contain this:
Not really handy yet... But by using the explode function, you can get something usefull out of it:
$values = explode("&", $query);
$name = explode("=", $values);
$name = $name;
$country = explode("=", $values);
$country = $country;
Now $name has the value dirk and $country holland...
Now you want this in your database.. depends very on what kind of database you use.. I suggest you read the manual found on devshed.com carefully, also on the subject how to get the output from html forms into php3....
Hope this gets you started...
November 7th, 1999, 03:05 PM
Except, in PHP, you don't need to worry about parsing variables from forms. Just use the variable names in your script, they will contain the values that were posted from the form.
November 7th, 1999, 06:02 PM
Donarb is right; you do not need to use getenv("QUERY_STRING") in PHP. It's much simpler than that.
If you have an element like:
<INPUT TYPE="text" NAME="country">
and the user enters "Holland" and submits the form, your receiving script will automatically have a variable called $country with the value "Holland".
You'll need to validate the data to make sure that some cracker isn't trying to slip illegal characters into your database (like, perhaps, backslashes or apostrophes). You can do that with the addslashes() function:
$country = addslashes ($country);
You can then use this validated variable in your SQL statement:
$sql = "UPDATE CustomerInfo SET Country='$country' WHERE RecID=$ID";
or something like that (depending, of course, on what kind of query you're attempting to run).
November 7th, 1999, 07:20 PM
Thanks for your help, I need specific info as to how to encode it into the form or how to directly input the data from the form. I tried <form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF ?>
can you please help me, the error says that the url cannot be found.