Thread: Html Form Help

    #1
  1. No Profile Picture
    tigertim
    Guest
    Devshed Newbie (0 - 499 posts)
    Can anyone please give me some code to tgake input from a html form and post it into my database.

    Thanks
    Tim
  2. #2
  3. No Profile Picture
    dirk
    Guest
    Devshed Newbie (0 - 499 posts)
    This is basicly done like this:

    The form sends it values like this to the action url:

    http://url.to.action/script.php3?name=dirk&country=Holland

    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:
    name=dirk&country=Holland

    Not really handy yet... But by using the explode function, you can get something usefull out of it:

    $values = explode("&", $query);
    $name = explode("=", $values[0]);
    $name = $name[1];
    $country = explode("=", $values[1]);
    $country = $country[1];

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

    Grtz,

    Dirk
  4. #3
  5. No Profile Picture
    donarb
    Guest
    Devshed Newbie (0 - 499 posts)
    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.
  6. #4
  7. No Profile Picture
    scollo
    Guest
    Devshed Newbie (0 - 499 posts)
    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);

    See:
    http://www.php.net/manual/function.addslashes.php3

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

    -- Christopher
  8. #5
  9. No Profile Picture
    tigertim
    Guest
    Devshed Newbie (0 - 499 posts)
    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.

    thanks
    tim

Similar Threads

  1. HELP Editing database through HTML form
    By kashaf in forum PHP Development
    Replies: 2
    Last Post: February 12th, 2004, 11:17 AM
  2. Replies: 9
    Last Post: January 29th, 2004, 07:33 AM
  3. How to get client email??Help plz
    By Gecko22 in forum ASP Programming
    Replies: 12
    Last Post: January 22nd, 2004, 01:40 PM
  4. not returning records when it should
    By aliaga61 in forum ASP Programming
    Replies: 3
    Last Post: January 16th, 2004, 10:57 AM
  5. 'Object required' error
    By aliaga61 in forum ASP Programming
    Replies: 1
    Last Post: January 16th, 2004, 08:48 AM

IMN logo majestic logo threadwatch logo seochat tools logo