I am using PHP and MySQL to add data to a database. When I add data to a form and submit the data I get a message saying the data has been successfully added. However when I view the database on phpMyAdmin all I see is a blank row with nothing in it!
The database is for storing new partners of the company
Here is the code.
<?php
error_reporting(E_ERROR);
if (isset($_POST["newpartner-submit"])) {
$typeofpartner = $_POST["TypeofPartner"];
$orgname = $_POST["OrganaizatoinName"];
$location = $_POST["location"];
$Address = $_POST["Address"];
$focalftastaff = $_POST["focalftastaff"];
$principalname = $_POST["PrincipalName"];
$Telephone = $_POST["Telephone"];
$Email = $_POST["npEmail"];
$Interests = $_POST["biginput1"];
$IndicateOrpotunities = $_POST["biginput2"];
$IndicatePartnership = $_POST["biginput3"];
$specify = $_POST["biginput4"];
$listkeychallenges = $_POST["biginput5"];
$partnershipAgreement = $_POST["PartnershipAgreementinplace"];
$Implementationdate = $_POST["implementationperiod"];
$agreementavailable = $_POST["PartnerAgrementAvailable"];
require_once 'dbh.inc.php';
require_once 'nptfunctions.inc.php';
if (emptyInputnewpartner($typeofpartner, $orgname, $location, $Address, $focalftastaff, $principalname, $Telephone, $Email, $Interests, $IndicateOrpotunities, $IndicatePartnership, $specify, $listkeychallenges) !== false) {
header("location: ../php/newpartner.php?error=emptyInput");
exit();
}
if (invalidAddress($Address) !== false) {
header("location: ../php/newpartner.php?error=invalidAddress");
exit();
}
if (invalidTelephone($Telephone) !==false) {
header("location: ../php/newpartner.php?error=invalidTelephoneNumber");
exit();
}
if (invalidnptEmail($Email) !== false) {
header("location: ../php/newpartner.php?error=invalidEmail");
exit();
}
createnpt($conn, $typeofpartner, $orgname, $location, $Address, $focalftastaff, $principalname, $Telephone, $Email, $Interests, $IndicateOrpotunities, $IndicatePartnership, $specify, $listkeychallenges, $partnershipAgreement, $Implementationdate, $agreementavailable);
}else {
header("location: ../php/newpartner.php");
exit();
}
dbh.inc.php code
<?php
$servername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "fta pms";
$conn = mysqli_connect($servername, $dbUsername, $dbPassword, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
nptfunctions.inc.php code
<?php
function emptyInputnewpartner($typeofpartner, $orgname, $location, $Address, $focalftastaff, $principalname, $Telephone, $Email, $Interests, $IndicateOrpotunities, $IndicatePartnership, $specify, $listkeychallenges) {
$result = null;
if (empty($typeofpartner) || empty($orgname) || empty($location) || empty($Address) || empty($focalftastaff) || empty($principalname) || empty($Telephone) || empty($Email) ||empty($Interests) || empty($IndicateOrpotunities) || empty($IndicatePartnership) || empty($specify) || empty($listkeychallenges)) {
$result = true;
} else {
$result = false;
}
return $result;
}
function invalidAddress($Address) {
$result = null;
if (preg_match("/^[a-zA-Z0-9]*$/", $Address)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function invalidTelephone($Telephone) {
$result = null;
if (!is_numeric($Telephone)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function invalidnptEmail($Email) {
$result = null;
if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function createnpt($conn, $typeofpartner, $orgname, $location, $Address, $focalftastaff, $principalname, $Telephone, $Email, $Interests, $IndicateOrpotunities, $IndicatePartnership, $specify, $listkeychallenges, $partnershipAgreement, $Implementationdate, $agreementavailable){
$sql = "INSERT INTO newpartner (typeofpartner, orgname, location, Address, focalftastaff, principalname, Telephone, Email, Interests, IndicateOrpotunities, IndicatePartnership, specify, listkeychallenges, partnershipAgreement, Implementationdate, agreementavailable) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../php/newpartner.php?error=stmtFailed");
exit();
}
mysqli_stmt_bind_param($stmt, "ssssssssssssssss", $typeofpartner, $orgname, $location, $Address, $focalftastaff, $principalname, $Telephone, $Email, $Interests, $IndicateOrpotunities, $IndicatePartnership, $specify, $listkeychallenges, $partnershipAgreement, $Implementationdate, $agreementavailable);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("location: ../php/newpartner.php?error=none");
exit();
}