"Hi!
I'm going to teach you how to create a profile form but before anything else you need to download and install first the phpmyadmin as your database.
This is how to create a Profile form where the user's data will input to that form and store in database.
Follow these steps in creating a database using phpmyadmin:
1. Open the installed phpmyadmin
2. You need to click the ""create table"" and name it as profile_form.
3. Save your database and name it as a resume.
4. When everything is done, click SQL and copy-paste the code given below:
CREATE TABLE IF NOT EXISTS 'details'(
'user_id' int(11) NOT NULL AUTO_INCREMENT,
'first_name' varchar(30) NOT NULL,
'last_name' varchar(30) Not NULL,
'address' varchar(100) NOT NULL,
'contact_num' int(30) NOT NULL,
'gender' varchar(10) NOT NULL,
PRIMARY KEY ('user_id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3
Note: the database given is just a simple ad contain of basic information only. You can add your own after following this steps.
After creating that database, you can now create the profile form just follow these steps:
1. Open your HTML code editor. (I recommend you to use notepad++)
2. Click on file menu bar and click new.
3. Save your form as index.php.
4. Copy and paste the code given below:
<form name=""profile"" action=""code_exec.php"" onsubmit=""return validateForm()"" method=""post"">
<table width=""274"" border=""0"" align=""center"" cellpadding=""2"" cellspacing=""0"">
<tr>
<td colspan=""2"">
<div align=""center"">
<?php
$remarks=$_GET['remarks'];
if ($remarks==null and $remarks=="""")
{
echo 'Input your PROFILE Here';
}
if ($remarks=='success')
{
echo 'Success';
}
?>
</div></td>
</tr>
<tr>
<td width=""95""><div align=""right"">First Name:</div></td>
<td width=""171""><input type=""text"" name=""first_name"" /></td>
</tr>
<tr>
<td><div align=""right"">Last Name:</div></td>
<td><input type=""text"" name=""last_name"" /></td>
</tr>
<tr>
<td><div align=""right"">Gender:</div></td>
<td><input type=""text"" name=""gender"" /></td>
</tr>
<tr>
<td><div align=""right"">Address:</div></td>
<td><input type=""text"" name=""address"" /></td>
</tr>
<tr>
<td><div align=""right"">Contact No.:</div></td>
<td><input type=""text"" name=""contact_num"" /></td>
</tr>
<tr>
<td><div align=""right""></div></td>
<td><input name=""submit"" type=""submit"" value=""Submit"" /></td>
</tr>
</table>
</form>
After creating the database and profile form you need to create a connection for the two copy-paste the code below:
<?php
$mysql_hostname = ""localhost"";
$mysql_user = ""root"";
$mysql_password = """";
$mysql_database = ""resume"";
$prefix = """";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(""Not connected to database"");
mysql_select_db($mysql_database, $bd) or die(""Not connected to database"");
?>
Then create a script where the input data save to the database and save as code_exec.php copy-paste the code below:
<?php
session_start();
include('connection.php');
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$gender=$_POST['gender'];
$address=$_POST['address'];
$contact_num=$_POST['contact_num'];
mysql_query(""INSERT INTO details(first_name, last_name, gender, address, contact_num)VALUES('$first_name', '$last_name', '$gender', '$address', '$contact_num')"");
header(""location: index.php?remarks=success"");
mysql_close($con);
?>
Validating the input is very important. This is used to make sure that all textfield is filled out before saving it to the database. Copy-paste the code below in the head tag of your registration form which you name as index.php:
<script type=""text/javascript"">
function validateForm()
{
var a=document.forms[""resume""][""first_name""].value;
var b=document.forms[""resume""][""last_name""].value;
var c=document.forms[""resume""][""gender""].value;
var d=document.forms[""resume""][""address""].value;
var e=document.forms[""resume""][""contact_num""].value;
if ((a==null || a=="""") && (b==null || b=="""") && (c==null || c=="""") && (d==null || d=="""") && (e==null || e==""""))
{
alert(""All TextField must be filled out"");
return false;
}
if (a==null || a=="""")
{
alert(""Type your First name"");
return false;
}
if (b==null || b=="""")
{
alert(""Type your Last name"");
return false;
}
if (c==null || c=="""")
{
alert(""Type your Gender"");
return false;
}
if (d==null || d=="""")
{
alert(""Type your address"");
return false;
}
if (e==null || e=="""")
{
alert(""Type your contact"");
return false;
}
}
</script>
After doing all the given steps and code above, this is done. I hope this will help you a lot."