Thank you very much for your reply. That’s kind of you.
The “emp.htm” is the code for a HTML form I want to save the incoming data entered through this form to the following MYSQL database table.
Database: hrms
Table: employee
Fields: empNo, Name, Address, Salary
I’m using Dreamweaver for coding and WAMP server for the other relevant works. I created a mySQL connection to the database (hrms). Then a folder called “connections” automatically created inside the folder (folder name is exercise) that I save my php and html files. In the connections folder there is a file called “conn.php”.
I have already created the database ‘hrms’ and the table ‘employee’ in phpmyAdmin.
My problem is even I have done everything correctly, once I enter the values to the fields of the Form and click Save button, it doesn’t save data to the table and getting the message “Error Occurred”
It’s great If you could help me to fix this problem.
“conn.php”:-
<?php
FileName="Connection_php_mysql.htm"
Type="MYSQL"
HTTP="true"
$hostname_conn = "localhost";
$database_conn = "hrms";
$username_conn = "root";
$password_conn = "";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
?>
“emp.htm”:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="testing.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
Employee No:
<input type="text" name="txtEmpNo" id="txtEmpNo" />
Name:
<input type="text" name="txtName" id="txtName" />
Address:
<input type="text" name="txtAddress" id="txtAddress" />
Salary:
<input type="text" name="txtSalary" id="txtSalary" />
<br /><br />
<input type="submit" name="save" id="save" value="Save" />
<input type="reset" name="clear" id="clear" value="Clear" />
<input type="submit" name="exit" id="exit" value="Exit" />
<br />
</form>
</body>
</html>
“testing.php”:-
<html>
<head>
</head>
<body>
<?php
$data=array($POST['txtEmpNo'],$POST['txtName'],$POST['txtAddress'],$POST['txtSalary']);
$server = "localhost";
$username = "root";
$password = "";
$conn = mysql_connect($server, $username, $password) or die("DB connection failed");
mysql_select_db("hrms",$conn) or die("unable to open DB");
$query="INSERT into 'employee' values($data[0],$data[1],$data[2],$data[3])";
if(mysql_query($query,$conn)){
print"Record added successfully"; }
else{
print"Error occured"; }
mysql_close($conn);
?>
</body>
</html>