Using this syntax I can add records in the fields but it always add 2 records. For example I input Ana as a name. The output would be 2 Ana. And if ever I delete one record, both records were deleted/ removed from the table. Here is the syntax for adding the record:
<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="inventory"; // Database name
$tbl_name="client"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inventory", $con);
$addclient="INSERT INTO client(account_name, maintenance_type, ma_status, ma_contract_start, ma_contract_end, ma_reference_no)
VALUES ('". $_POST['account_name'] . "', '". $_POST['maintenance_type'] . "', '". $_POST['ma_status'] . "', '". $_POST['ma_contract_start'] . "', '". $_POST['ma_contract_end'] . "', '". $_POST['ma_reference_no'] . "')";
mysql_query($addclient,$con);
if (!mysql_query($addclient,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
The first call to ‘mysql_query’ executes the command once.
The second one in the ‘if’ clause, does the query again.
Try this: