Hi
I am new to this but need urgent help for a project
I downloaded xamp and it is running
I created DB on PHPMyadmin and try to connect my php file to it from a html form
Here is code attached.
Wish some one help me with it
The file html file and php file are saved in xamp/htdocs
Database and output attached
My HTML
output
I am new to this but need urgent help for a project
I downloaded xamp and it is running
I created DB on PHPMyadmin and try to connect my php file to it from a html form
Here is code attached.
Wish some one help me with it
The file html file and php file are saved in xamp/htdocs
Database and output attached
Code:
<?php
// database connection code
if(isset($_POST['Submit']))
{
// $con = mysqli_connect('localhost', 'database_user', 'database_password','database');
$con = mysqli_connect('localhost', 'root', '','db_connect');
// get the post records
$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtRole = $_POST['txtRole'];
$txtArea = $_POST['txtArea'];
$txtRegion = $_POST['txtRegion'];
// database insert SQL code
$sql = "INSERT INTO `employees` (`id`, `name`, `email`, `role`, `solution_area` , `region`) VALUES ('0', '$txtName', '$txtEmail', '$txtRole', '$txtArea' ,'$txtRegion')";
// insert in database
$rs = mysqli_query($con, $sql);
echo $rs;
if($rs)
{
echo "Contact Records Inserted";
echo "New record has id: " . mysqli_insert_id($con);
}
else
{
echo "Are you a genuine visitor?";
}
}
?>
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form - PHP/MySQL Demo Code</title>
</head>
<body>
<fieldset>
<legend>Contact Form</legend>
<form name="frmContact" method="post" action="contact.php">
<p>
<label for="Name">Name </label>
<input type="text" name="txtName" id="txtName">
</p>
<p>
<label for="email">Email</label>
<input type="text" name="txtEmail" id="txtEmail">
</p>
<p>
<label for="role">Role</label>
<input type="text" name="txtRole" id="txtRole">
</p>
<p>
<label for="area">Solution-Area</label>
<textarea name="txtArea" id="txtArea"></textarea>
</p>
<p>
<label for="region">Region</label>
<textarea name="txtRegion" id="txtRegion"></textarea>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
</fieldset>
</body>
</html>