Log in

View Full Version : php customer details form



nikomou
04-10-2007, 07:40 AM
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!

codeexploiter
04-10-2007, 10:37 AM
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



$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

mburt
04-10-2007, 10:38 AM
<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.

boogyman
04-10-2007, 01:19 PM
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

nikomou
04-10-2007, 11:57 PM
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

boogyman
04-11-2007, 12:54 AM
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
// 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


<input name="email" type="text" value="" />