In this article we will learn about some of the frequently asked HTML programming questions in technical like “connect html to mysql database” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on html was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in HTML. Below are some solution about “connect html to mysql database” Code Answer’s.
connect html to mysql database
xxxxxxxxxx
1
<?php
2
// database connection code
3
// $con = mysqli_connect('localhost', 'database_user', 'database_password','database');
4
5
$con = mysqli_connect('localhost', 'root', '','db_connect');
6
7
// get the post records
8
$txtName = $_POST['txtName'];
9
$txtEmail = $_POST['txtEmail'];
10
$txtPhone = $_POST['txtPhone'];
11
$txtMessage = $_POST['txtMessage'];
12
13
// database insert SQL code
14
$sql = "INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage')";
15
16
// insert in database
17
$rs = mysqli_query($con, $sql);
18
19
if($rs)
20
{
21
echo "Contact Records Inserted";
22
}
23
24
?>
connect html to mysql database
xxxxxxxxxx
1
$con = mysqli_connect("localhost","your_localhost_database_user","your_localhost_database_password","your_localhost_database_db");
2
connect html to mysql database
xxxxxxxxxx
1
$con = mysqli_connect('localhost', 'root', '',’db_connect’);
2
The “db_connect” is our database name that we created before.
3
After connection database you need to take post variable from the form. See the below code
4
$txtName = $_POST['txtName'];
5
$txtEmail = $_POST['txtEmail'];
6
$txtPhone = $_POST['txtPhone'];
7
$txtMessage = $_POST['txtMessage'];
connect html to mysql database
xxxxxxxxxx
1
<?php
2
//Step1
3
$db = mysqli_connect('localhost','username','password','database_name')
4
or die('Error connecting to MySQL server.');
5
?>
6
7
<html>
8
<head>
9
</head>
10
<body>
11
<h1>PHP connect to MySQL</h1>
12
</body>
13
</html>
14