Caffrey
Tech User Experience Designer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
Related Code: User Registration Form Using PHP
In this tutorial, we are going to learn on How To Create Contact Form Using PHP. We have a contact form in the example below for the user to send their message, suggestions, questions, feedback, and clarifications about your work or your website.
We have three fields as full name, email, and message in our contact form. This is a very simple tutorial, hope you will find this useful.
Contact Form - HTML
This source code for our contact form.
Data Table
This is the data where the user message shows in this table.
And, we have CSS style.
Contact Form Input Into Database
This is PHP query where our data store in the database. First, create a database table, name into "contact_form".
After executing the query code above it will be added to the database, this is the result.
Related Code: User Registration Form Using PHP
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Download
In this tutorial, we are going to learn on How To Create Contact Form Using PHP. We have a contact form in the example below for the user to send their message, suggestions, questions, feedback, and clarifications about your work or your website.
We have three fields as full name, email, and message in our contact form. This is a very simple tutorial, hope you will find this useful.
Contact Form - HTML
This source code for our contact form.
- <form
name
=
"frmContact"
method
=
"post"
action
=
""
>
- <div
class
=
"aler_message"
><?php if(
isset(
$message)
)
{
echo $message; }
?></
div
>
- <table
border
=
"0"
cellpadding
=
"10"
cellspacing
=
"1"
width
=
"500"
align
=
"center"
>
- <tr
class
=
"tableheader"
>
- <td
colspan
=
"2"
>
Contact Form</
td
>
- </
tr
>
- <tr
class
=
"tablerow"
>
- <td
>
Full Name<br
/
>
<input
type
=
"text"
class
=
"text_input"
autofocus=
"autofocus"
name
=
"fullname"
></
td
>
- <td
>
Email<br
/
>
<input
type
=
"text"
class
=
"text_input"
autofocus=
"autofocus"
name
=
"email"
></
td
>
- </
tr
>
- <tr
class
=
"tablerow"
>
- <td
colspan
=
"2"
>
Message<br
/
><textarea
name
=
"user_message"
class
=
"text_input"
autofocus=
"autofocus"
cols
=
"60"
rows
=
"6"
></
textarea
></
td
>
- </
tr
>
- <tr
class
=
"tableheader"
>
- <td
colspan
=
"2"
><input
type
=
"submit"
class
=
"btn_submit"
name
=
"submit"
value
=
"Submit"
></
td
>
- </
tr
>
- </
table
>
- </
form
>
Data Table
This is the data where the user message shows in this table.
- <table border="1" class="table_data" cellspacing="5" cellpadding="5">
- <tr style="color:blue;">
- <th>
- Full Name
- </th>
- <th>
- Email
- </th>
- <th>
- Message
- </th>
- </tr>
- <?php
- $conn
=
mysql_connect
(
"localhost"
,
"root"
,
""
)
;
- mysql_select_db
(
"contact_form"
,
$conn
)
;
- $result
=
mysql_query
(
"select * from tbl_contact order by tbl_contact_id DESC "
)
or die
(
mysql_error
(
)
)
;
- while
(
$row
=
mysql_fetch_array
(
$result
)
)
{
- $id
=
$row
[
'tbl_contact_id'
]
;
- ?>
- <tr style="text-align:center; color:blue;">
- <td style="width:200px;">
- <?php
echo
$row
[
'fullname'
]
;
?>
- </td>
- <td style="width:200px; color:red;">
- <?php
echo
$row
[
'email'
]
;
?>
- </td>
- <td style="width:200px; color:blue;">
- <?php
echo
$row
[
'user_message'
]
;
?>
- </td>
- </tr>
- <?php
}
?>
- </table>
And, we have CSS style.
- table
{
- border
:
yellow
5px
solid
;
- }
- .table_data
{
- margin-left
:
291px
;
- margin-top
:
20px
;
- }
- .tableheader
{
- background-color
:
maroon
;
- color
:
white
;
- font-weight
:
bold
;
- font-size
:
25px
;
- }
- .tablerow
{
- background-color
:
black
;
- color
:
white
;
- font-size
:
20px
;
- font-weight
:
bold
;
- }
- .aler_message
{
- color
:
#FF0000
;
- font-weight
:
bold
;
- text-align
:
center
;
- width
:
100%
;
- cursor
:
pointer
;
- }
- .text_input
{
- font-size
:
18px
;
- border
:
blue
1px
solid
;
- background
:
azure
;
- text-indent
:
10px
;
- cursor
:
pointer
;
- }
- .btn_submit
{
- font-size
:
18px
;
- width
:
100px
;
- background
:
azure
;
- border
:
blue
1px
solid
;
- padding
:
6px
;
- border-radius
:
8px
;
- color
:
blue
;
- cursor
:
pointer
;
- }
- .btn_submit
:
hover
{
- font-size
:
18px
;
- width
:
100px
;
- background
:
azure
;
- border
:
re 1px
solid
;
- padding
:
6px
;
- border-radius
:
8px
;
- color
:
red
;
- cursor
:
pointer
;
- }
Contact Form Input Into Database
This is PHP query where our data store in the database. First, create a database table, name into "contact_form".
- $conn
=
mysql_connect
(
"localhost"
,
"root"
,
""
)
;
- mysql_select_db
(
"contact_form"
,
$conn
)
;
- mysql_query
(
"INSERT INTO tbl_contact (fullname, email, user_message) VALUES ('"
.
$fullname
.
"', '"
.
$email
.
"','"
.
$user_message
.
"')"
)
;
After executing the query code above it will be added to the database, this is the result.


Related Code: User Registration Form Using PHP
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Download
You must upgrade your account or reply in the thread to view hidden text.