Results 1 to 6 of 6

Thread: php customer details form

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default php customer details form

    hey! i want to have a quick form for my customers to fill in, before i redirect them to an external website..

    I want the form to save the following details to a mysql database:
    Title - drop down list
    First Name
    Last Name
    Email

    hidden - date / time
    hidden - product name
    hidden - deal name
    hidden - merchant name
    hidden - generated unique id?

    is it also posible to embed a form within a table? so i could format the way it looks?!

    thanks guys / gals!

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I don't understand your question completely especially regarding the hidden field parts. I've made some changes in my code which will give you the same result.

    In the demo i've preset the values of the hidden fields that you can change with your strategy.

    The source code I provide doesn't have any form validation script either but a PHP script that collect and perform the table insertion.

    You need to do the following thing before executing the page.

    1. You need to create a table in your selected database with the following structure

    field data type

    id varchar(25)
    fname varchar(25)
    lname varchar(25)
    email varchar(25)
    product varchar(25)
    merchant varchar(25)
    deal varchar(25)
    dateofvisit date

    2. Edit my PHP code (rand.php) and change the following items with your database configuration

    Code:
    $user = "root"; //specify your db user
    
    $passwd = "";//specify your db user's password
    
    $db = "newTest";//specify your db name
    3. I've attached both the htm page as well as the php page as the attachment.

    4. Unzip and place both the file together in your web publishing folder

    5. Browse the rand1.htm file and enter the required data

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <form method="post">
    Title:
    <select name="title">
    <option value="values_here">Options Here</option>
    </select>
    <br>First Name:
    <input type="text" name="fname">
    <br>Last Name:
    <input type="text" name="lname">
    <br>E-mail:
    <input type="text" name="email">
    <br><input type="hidden" name="date" value="<?php echo date ('d,m,Y'); ?>">
    <input type="hidden" name="product">
    <input type="hidden" name="deal">
    <input type="hidden" name="merchant">
    <input type="hidden" name="generated unique">
    </form>
    http://php-mysql-tutorial.com/
    That'll describe to you how to hook up a MySql database, and insert content.

    edit// sorry codexploiter, cross-posted.
    - Mike

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    is it also posible to embed a form within a table? so i could format the way it looks?!
    yes, but I would suggest you look into using html and css as it will provide better customability and alot more options in what you would like to do

  5. #5
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thank you codeexploiter..

    your code was great!

    Do you happen to have a quick validation script? just wanna make sure all the fields are there, and that the email address is in the right format!

    cheers

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Do you happen to have a quick validation script? just wanna make sure all the fields are there, and that the email address is in the right format!

    PHP Code:

    <?php
    // Takes any fields that were sent to the browser and makes sure that that its not empty, 
    // and writes any field that is empty to an array to be printed later
    foreach($_POST as $key => $value) {
      if(!isset(
    trim($value))) {
         
    $err_list[] = $key " is a required field!";
      }
    }

    // Validates email
    $email $_POST['email'];
    if(!
    preg_match('/^[A-z0-9_\-]+\@(A-z0-9_-]+\.)+[A-z]{2,4}$/'$email); ) {
      
    $err_list[] =  $email" is not a valid email!";
    }

    // Prints out all errors
    echo "<ul>";
    foreach(
    $err_list as $err) {
      echo 
    "<li>" $err "</ul> \n";
    }
    echo 
    "</ul>";

    ?>

    <p><a href="history.go(-1)">Fix Errors</a></p>
    where $_POST['email'] is the "name" of the email input field

    Code:
    <input name="email" type="text" value="" />
    Last edited by boogyman; 04-11-2007 at 02:14 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •