The code below will:
1. Connect to a database (The user name, password and database name are in red, and must be provided by you).
2. Insert records into the database fields named in green, getting that data from form field names in blue.

Here's a page up that will write this code automatically for you - Both the code to create a table and the form to insert a record!

IN ORDER TO DO ALL THIS YOU MUST FIRST HAVE A LUNARPAGES ACCOUNT WITH MySQL AND:
1. Create a database in your control panel.
2. Create a database user in your control panel, and attach that user to your database. This is separate from your Lunar Pages account user name, and pertains only to the database.
3. Create a table for your database, with fields. If you're not sure, a safe bet for the field types is VARCHAR, and size for each field should be at least 32 - 128, except for an email or link field, which should be 255.

ONCE YOUR DATABASE IS SET UP WITH A USER:
Go and create your table and insert form or:
1. Copy what's below, then paste it into an empty notepad window. This will get rid of the underlying html. It will lose its colors, but you can refer back to this page, or just print this page.
2. Now, select and copy it off the notepad, and paste it into your html page as code. You can also just use Notepad as an editor, if you know a bit about coding.
3. Replace the red with the proper information.
4. Replace the green with the field names in your database.
5. Replace the blue with the field names in your form. The fields in your form are what will insert data into your database. Make sure the form field names in the form match the form field names in the blue!
6. Name your page with an extension of .php and upload. It should work.
REMEMBER: All punctuation in the script must stay the same. Database names, data table names, user, password and form field names are all CASE sEnSiTiVe!
The regular html codes like HTML, BODY, HEAD, etc...are not included here, but can be put in before and after this code.
If you use this and it doesn't work, please let me know by posting in the PHP-MySQL Forum. Thanks, and have fun!

<?php
if (isset($_POST['submit'])){
$dbcnx = @mysql_connect( "localhost", "USER_NAME", "PASSWORD");
mysql_select_db("DATABASE_NAME");

$fname=$_POST['fname'];
$lname=$_POST['lname'];
$fname=$_POST['address'];

//..you can create variable names and plug in the form field values as above. It may be wise to put in code similar to what you
// find on forms that have security measures included to keep people from injecting headers into the form data.

// Give variable names to all your incoming posts (after applying security measures) and then you can plug the variable names

// into your insert code as below:

$sql = "INSERT INTO TABLE_NAME SET " .
"Name_First='$fname', " .
"Name_Last='$lname', " .
"Address='$address', " .
"State='$state', " .
"Zip='$Zip', " .
"EMail='$email'";
if (mysql_query($sql)) {

echo("<P>New Record Added</P>");
}

else {

echo("<P>Error adding new record: " .
mysql_error() . "</P>");
}

}
?>

<P><A HREF="<?php echo($_SERVER['PHP_SELF']); ?>">Add another record</A></P>
<?php else: // Enter another record?>

<FORM ACTION="<?php echo($_SERVER['PHP_SELF']); ?>" METHOD=POST>

<P>Please enter your information below<BR>
Name:
<INPUT TYPE=TEXT NAME="fname" SIZE=22MAXLENGTH=100>
<input type=TEXT name="lname" size=30MAXLENGTH=100>
<br>
Address:
<input type=TEXT name="address" size=44MAXLENGTH=100>
<br>
City:
<input type=TEXT name="city" size=28MAXLENGTH=100>
<br>
State:
<input type="text name="state" size=18MAXLENGTH=30><br>
Zip:
<input type=TEXT name="zip" size=18MAXLENGTH=100>
<BR>
eMail:
<input type=TEXT name="email" size=44MAXLENGTH=100>
<BR>
<INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"> << This is what the code looks for at
t
he first line of code above with "if (isset($_POST[$submit)){</P>
</FORM>
<?php endif; ?>

 

Press H for TWebMan Home | J for JavaScript | P for Make A Perl Script | A for Autorepaircd.Com | T for Tsoft