form not responding to query - php

I am currently working on php and html form. I want to check if duplicate user or email is there. below is my html code.
<div class="container" align="center">
<form method="post" class="form-horizontal" action="signup.php">
<?php include('errors.php');?>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
<label class="col-sm-4 control-label">Full name</label>
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="First_Name" placeholder="First name" <?php echo $First_Name?> />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="Last_Name" placeholder="Last name" <?php echo $Last_Name?> />
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
<label class="control-label">Username</label>
</div>
<div class="col-xs-6">
<input type="text" class="form-control" name="Username" <?php echo $Username?>/>
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-envelope"></span>
<label class="control-label">Email address</label>
</div>
<div class="col-xs-6">
<input type="text" class="form-control" name="Email" <?php echo $Email?>/>
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-lock"></span>
<label class="control-label">Password</label>
</div>
<div class="col-xs-6">
<input type="password" class="form-control" name="Password_1" />
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-lock"></span>
<label class="control-label">Confirm Password</label>
</div>
<div class="col-xs-6">
<input type="password" class="form-control" name="Password_2" />
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-info"></span>
<label class="control-label">Gender</label>
</div>
<div class="col-xs-6">
<div class="radio">
<label>
<input type="radio" name="Gender" value="male" /> Male
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="Gender" value="female" /> Female
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="Gender" value="other" /> Other
</label>
</div>
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-date"></span>
<label class="control-label">Date of birth</label>
</div>
<div class="col-xs-6">
<input type="date" class="form-control" name="Birthday" placeholder="YYYY/MM/DD" <?php echo $Birthday?>/>
</div>
</div>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-home"></span>
<label class="control-label">Address</label>
</div>
<div class="col-xs-5">
<textarea placeholder="Enter Address Here.." rows="3" name="Address" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button type="submit" class="btn btn-primary" name="reg_user">Submit</button>
</div>
</div>
</form>
</div>
here is my datapost file
<html>
<body>
<?php
include 'databaseconn.php';
print_r($_POST);
$First_Name = "";
$Last_Name= "";
$Username= "";
$Email= "";
$Password_1="";
$Password_2="";
$Gender= "";
$Birthday= "";
$Address= "";
$errors = array();
if (isset($_POST['reg_user']))
{
$First_Name = mysqli_real_escape_string($connect,$_POST['First_Name']);
$Last_Name= mysqli_real_escape_string($connect,$_POST['Last_Name']);
$Username= mysqli_real_escape_string($connect,$_POST['Username']);
$Email= mysqli_real_escape_string($connect,$_POST['Email']);
$Password_1=mysqli_real_escape_string($connect,$_POST['Password_1']);
$Password_2=mysqli_real_escape_string($connect,$_POST['Password_2']);
$Gender=mysqli_real_escape_string($connect,$_POST['Gender']);
$Birthday=mysqli_real_escape_string($connect,$_POST['Birthday']);
$Address=mysqli_real_escape_string($connect,$_POST['Address']);
if (empty($First_Name))
{
array_push($errors,"First name is required");
}
if (empty($Last_Name))
{
array_push($errors,"Last name is required");
}
if (empty($Username))
{
array_push($errors,"Username is required");
}
if (empty($Email))
{
array_push($errors,"Email id is required");
}
if (empty($Password_1))
{
array_push($errors,"Password is required");
}
if ($Password_1 != $Password_2)
{
array_push($errors,"Two password do not match");
}
if (empty($Gender))
{
array_push($errors,"Gender is required");
}
if (empty($Birthday))
{
array_push($errors,"Birthday is required");
}
if (empty($Address))
{
array_push($errors,"Address is required");
}
}
$user_check_query= "SELECT * FROM `user_data` WHERE Username='$Username' OR Email ='$Email' LIMIT 1";
$result = mysqli_query($connect, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user)
{
if($user['Username'] === $Username)
{
array_push($errors, "Username already exists");
}
if($user['Email'] === $Email)
{
array_push($errors, "Email already exists");
}
}
if (count($errors) == 0)
{
$Password = md5($Password_1);
mysqli_query($connect, "INSERT INTO `user_data` (`First_Name`, `Last_Name`, `Username`, `Email`, `Password`, `Gender`, `Birthday`, `Address`) VALUES ('$First_Name', '$Last_Name', '$Username', '$Email', '$Password', '$Gender', '$Birthday', '$Address')");
}
if(mysqli_affected_rows($connect)>0)
{
echo'<p> User successfully registered </p>';
echo' Go BAck ';
}
else
{
echo 'Registration not successfull';
echo 'mysqli_error($connect)';
}
?>
</body>
</html>
and my database connection file is
<?php
$servername = "localhost";
$username = "root";
$password = "";
$databasename="smartparking";
// Create connection
$connect = mysqli_connect($servername, $username, $password,$databasename);
// Check connection
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
when I run the code and enter data, it doesn't add data to the database. it is checking for username and email. but data is not inserted for the new users.

Related

isset function not working correctly

I am trying to insert records into a table but I am facing a problem on the isset function. I am unable to process the code.
In the following code the else statement is executed instead of the isset function.
<?php
if (isset($_POST['submit'])) {
include_once 'dbh.inc.php';
$firstname = mysqli_real_escape_string($conn, $_POST['firstname']);
$surname = mysqli_real_escape_string($conn, $_POST['surname']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);
$bdate = mysqli_real_escape_string($conn, $_POST['bdate']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
if(empty($firstname) || empty($surname) || empty($email) || empty($username) || empty($password) || empty($cpassword) || empty($bdate) || empty($gender)) {
header("Location: ../index.php?index=empty");
exit();
} else {
$sql = "SELECT * FROM users WHERE username='$username'";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header("Location: ../index.php?index=username already taken");
exit();
} else {
// Hashing the password
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
//Insert users into the database
$sql = "INSERT INTO users (id, firstname, surname, email, username, password, bdate, gender) VALUES ('', '$firstname', '$surname', '$email', '$username', '$password', '$bdate', '$gender');";
mysqli_query($conn, $sql);
header("Location: ../profile.php");
exit();
}
}
} else {
header("Location: ../index.php?index=error");
exit();
}
Here is the front-end containing the "sign up" part:
<div class="container and">
<div class="row">
<div class="col-lg-6 pull-right">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Create a new account.</h3>
</div>
<div class="panel-body">
<form id="loginform" action="includes/signup.inc.php" method="POST">
<div class="row">
<div class="form-group has-error col-md-6">
<input type="text" class="form-control" name="firstname" placeholder="First Name">
</div>
<div class="form-group has-error col-md-6">
<input type="text" class="form-control" name="surname" placeholder="Surname">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-12">
<input type="text" class="form-control" name="email" placeholder="Email Address">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-12">
<input type="text" class="form-control" name="username" placeholder="Username">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-12 padding-top-10">
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-12">
<input type="password" class="form-control" name="cpassword" placeholder="Confirm Password">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-12">
<h4> Birthday</h4>
<input type="date" class="form-control" name="bdate" value="birthdate">
</div>
</div>
<div class="row padding-top-10">
<div class="form-group has-error col-md-6 padding-top-10">
<div class="pull-right">
Male: <input type="radio" name="gender" value="male" />
</div>
</div>
<div class=" form-group has-error col-md-6 padding-top-10">
Female: <input type="radio" name="gender" value="female">
</div>
</div>
<div class="padding-top-10">
<button class="btn btn-success" name="submit">Create Account</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
You missed the button type attribute which will be type="submit" If you didn't include this type attribute, the form will not submit data.
Your code:
<button class="btn btn-success" name="submit">Create Account</button>
It should be:
<button type="submit" class="btn btn-success" name="submit">Create Account</button>
If, this is not your problem, let me know! Thanks.

Data from row into no php-site for edit

I have a problem with my php-code. On the first site is a list with all the data. The table of the data is correctly displayed. In the last column of the table is a link placed to the next page which should hand over the id of the row.
Here's the link:
print 'Ändern';
But I can't now get the data into the input fields for edit. The form show up correct, but i have in every input field this error:
Warning: Illegal string offset 'vorname' in /home_pr5/d/e/deniseli.ch/htdocs/www.deniseli.ch/T .... tor/editsr.php on line 130S
Here's the editsr.php:
<?php
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = $id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch();
include("templates/header.inc.php");
if(isset($_GET['save'])) {
$save = $_GET['save'];
if($save == 'personal_data') {
$vorname = trim($_POST['vorname']);
$nachname = trim($_POST['nachname']);
$adresse = trim($_POST['adresse']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$geburtstag = trim($_POST['geburtstag']);
$handy = trim($_POST['handy']);
$liga = trim($_POST['liga']);
$verein = trim($_POST['verein']);
$bank = trim($_POST['bank']);
$iban = trim($_POST['iban']);
if($vorname == "" || $nachname == "" || $adresse == "" || $plz == "" || $ort == "" || $handy == "" || $liga == "" || $verein == "") {
$error_msg = "Bitte alle Angaben ausfüllen.";
} else {
$statement = $pdo->prepare("UPDATE users SET vorname = :vorname, nachname = :nachname, adresse = :adresse, plz = :plz, ort = :ort, geburtstag = :geburtstag, handy = :handy, liga = :liga, verein = :verein, bank = :bank, iban = :iban, id = :id, updated_at=NOW() WHERE id = $id");
$result = $statement->execute(array('vorname' => $vorname, 'nachname'=> $nachname,'adresse' => $adresse, 'plz' => $plz, 'ort' => $ort, 'geburtstag' => $geburtstag, 'handy' => $handy, 'liga' => $liga, 'verein' => $verein,'bank' => $bank, 'iban' => $iban, 'id' => $user['id'] ));
$success_msg = "Daten erfolgreich gespeichert.";
}
} else if($save == 'email') {
$passwort = $_POST['passwort'];
$email = trim($_POST['email']);
$email2 = trim($_POST['email2']);
if($email != $email2) {
$error_msg = "Die eingegebenen E-Mail-Adressen stimmten nicht überein.";
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_msg = "Bitte eine gültige E-Mail-Adresse eingeben.";
} else if(!password_verify($passwort, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$statement = $pdo->prepare("UPDATE users SET email = :email WHERE id = $id");
$result = $statement->execute(array('email' => $email));
$success_msg = "E-Mail-Adresse erfolgreich gespeichert.";
}
} else if($save == 'passwort') {
$passwortAlt = $_POST['passwortAlt'];
$passwortNeu = trim($_POST['passwortNeu']);
$passwortNeu2 = trim($_POST['passwortNeu2']);
if($passwortNeu != $passwortNeu2) {
$error_msg = "Die eingegebenen Passwörter stimmten nicht überein.";
} else if($passwortNeu == "") {
$error_msg = "Das Passwort darf nicht leer sein.";
} else if(!password_verify($passwortAlt, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$passwort_hash = password_hash($passwortNeu, PASSWORD_DEFAULT);
$statement = $pdo->prepare("UPDATE users SET passwort = :passwort WHERE id = $id");
$result = $statement->execute(array('passwort' => $passwort_hash));
$success_msg = "Passwort erfolgreich gespeichert.";
}
}
}
?>
<div class="container main-container">
<h1>Schiedsrichter Profil bearbeiten</h1>
<?php
if(isset($success_msg) && !empty($success_msg)):
?>
<div class="alert alert-success">
×
<?php echo $success_msg; ?>
</div>
<?php
endif;
?>
<?php
if(isset($error_msg) && !empty($error_msg)):
?>
<div class="alert alert-danger">
×
<?php echo $error_msg; ?>
</div>
<?php
endif;
?>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Übersicht</li>
<li role="presentation">Persönliche Daten</li>
<li role="presentation">E-Mail</li>
<li role="presentation">Passwort</li>
</ul>
<!-- Übersicht-->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
<br>
<form action="?save=personal_data&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for=inputVorname class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" readonly>
</div>
</div>
</form>
</div>
<!-- Persönliche Daten-->
<div role="tabpanel" class="tab-pane" id="data">
<br>
<form action="?save=personal_data&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" placeholder="01.01.2000">
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" placeholder="Postfinance">
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" placeholder="CHxx xxxx xxxx xxxx xxxx x">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='internal.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
<!-- Änderung der E-Mail-Adresse -->
<div role="tabpanel" class="tab-pane" id="email">
<br>
<p>Zum Änderen deiner E-Mail-Adresse gib bitte dein aktuelles Passwort sowie die neue E-Mail-Adresse ein.</p>
<form action="?save=email&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwort" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail2" class="col-sm-2 control-label">E-Mail (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail2" name="email2" type="email" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='spielliste.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
<!-- Änderung des Passworts -->
<div role="tabpanel" class="tab-pane" id="passwort">
<br>
<p>Zum Änderen deines Passworts gib bitte dein aktuelles Passwort sowie das neue Passwort ein.</p>
<form action="?save=passwort&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Altes Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwortAlt" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu" class="col-sm-2 control-label">Neues Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu" name="passwortNeu" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu2" class="col-sm-2 control-label">Neues Passwort (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu2" name="passwortNeu2" type="password" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='spielliste.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include("templates/footer.inc.php")
?>
UPDATE: new code editsr.php. Works fine with the tabs, only the changes displayed after refresh the site.
Look at your code carefully
on the top you are using the $user variable like below
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch(); // here
and again on the bottom of php code you are using $user variable like below
$id = $_GET['id'];
$user = "SELECT * FROM users WHERE id = :id"; // here
?>
on the input you are trying to get like htmlentities($user['vorname']);
<div class="form-group">
<label for=inputVorname class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" readonly>
</div>
</div>
that's the problem of error in every input :)
New Code with only one form:
<?php
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = $id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch();
include("templates/header.inc.php");
if(isset($_GET['save'])) {
$save = $_GET['save'];
if($save == 'personal_data') {
$vorname = trim($_POST['vorname']);
$nachname = trim($_POST['nachname']);
$adresse = trim($_POST['adresse']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$geburtstag = trim($_POST['geburtstag']);
$handy = trim($_POST['handy']);
$email = trim($_POST['email']);
$liga = trim($_POST['liga']);
$verein = trim($_POST['verein']);
$bank = trim($_POST['bank']);
$iban = trim($_POST['iban']);
$passwortNeu = trim($_POST['passwortNeu']);
if($vorname == "" || $nachname == "" || $adresse == "" || $plz == "" || $ort == "" || $handy == "" || $liga == "" || $verein == "" || $email == "" || $passwortNeu == "" ){
$error_msg = "Bitte alle Angaben ausfüllen.";
} else {
$passwort_hash = password_hash($passwortNeu, PASSWORD_DEFAULT);
$statement = $pdo->prepare("UPDATE users SET vorname = :vorname, nachname = :nachname, adresse = :adresse, plz = :plz, ort = :ort, geburtstag = :geburtstag, handy = :handy, liga = :liga, verein = :verein, bank = :bank, iban = :iban, passwort = :passwort, email = :email, updated_at=NOW() WHERE id = $id");
$result = $statement->execute(array('vorname' => $vorname, 'nachname'=> $nachname,'adresse' => $adresse, 'plz' => $plz, 'ort' => $ort, 'geburtstag' => $geburtstag, 'handy' => $handy, 'liga' => $liga, 'verein' => $verein,'bank' => $bank, 'iban' => $iban, 'passwort' => $passwort_hash, 'email' => $email));
$success_msg = "Daten erfolgreich gespeichert.";
}
}
}
?>
<div class="container main-container">
<h1>Schiedsrichter Profil bearbeiten</h1>
<?php
if(isset($success_msg) && !empty($success_msg)):
?>
<div class="alert alert-success">
×
<?php echo $success_msg; ?>
</div>
<?php
endif;
?>
<?php
if(isset($error_msg) && !empty($error_msg)):
?>
<div class="alert alert-danger">
×
<?php echo $error_msg; ?>
</div>
<?php
endif;
?>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Persönliche Daten</li>
</ul>
<!-- Persönliche Daten-->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="data">
<br>
<form action="?save=personal_data" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" placeholder="01.01.2000">
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" placeholder="Postfinance">
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" placeholder="CHxx xxxx xxxx xxxx xxxx x">
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu" class="col-sm-2 control-label">Neues Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu" name="passwortNeu" type="password" value="<?php echo htmlentities($user['passwort']); ?>" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='internal.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include("templates/footer.inc.php")
?>

PHP form not submitting correctly

I have a form that displays user data based on a query. The form is meant to allow users to update their user account information. i.e., First name, Last name, Email address, etc.
account.php - form
<form class="form-horizontal" role="form" method="post" action="">
<div class="form-group">
<label class="col-lg-3 control-label">First name:</label>
<div class="col-lg-8">
<input class="form-control" name="fName" type="text" placeholder="<?php echo $fName ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Last name:</label>
<div class="col-lg-8">
<input class="form-control" name="lName" type="text" placeholder="<?php echo $lName ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" name="emailAddress" type="text" placeholder="<?php echo $emailAddress ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Username:</label>
<div class="col-md-8">
<input class="form-control" name="username" type="text" placeholder="<?php echo $username ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Password:</label>
<div class="col-md-8">
<input class="form-control" name="password" type="password">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Confirm password:</label>
<div class="col-md-8">
<input class="form-control" name="confirmPassword" type="password">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" value="Update" name="updateaccount" type="button">
<span></span>
<input class="btn btn-default" value="Cancel" type="reset">
</div>
</div>
</form>
updateaccount.php
<?php
$msg = "";
if(isset($_POST["updateaccount"]))
{
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$username = $_POST["username"];
$emailAddress = $_POST["emailAddress"];
$password = $_POST["password"];
$fName = mysqli_real_escape_string($db, $fName);
$lName = mysqli_real_escape_string($db, $lName);
$username = mysqli_real_escape_string($db, $username);
$emailAddress = mysqli_real_escape_string($db, $emailAddress);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password);
$sql="SELECT emailAddress FROM users WHERE emailAddress='$emailAddress'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1)
{
$msg = "Sorry...This email already exists";
}
else
{
$query = mysqli_query($db, "INSERT INTO users (fName, lName, username, emailAddress, password)VALUES ('$fName', '$lName', '$username', '$emailAddress, '$password')");
if($query)
{
$msg = "Your account has been updated";
}
}
}
?>
The above code is called on the account.php page:
include ("getuseraccount.php");
Did I miss something?
You are using input type button instead of submit for the Update button. Use 'submit' type instead of 'button' type.
<input class="btn btn-primary" value="Update" name="updateaccount" type="button">
try
<input class="btn btn-primary" value="Update" name="updateaccount" type="submit">
Unless you're using Ajax to submit the form (which you made no mention of, you need to add the file that you are submitting the form information to.
<form class="form-horizontal" role="form" method="post" action="updateaccount.php">

how to get the data added verification message at the same page of form

i have this page named courses.php contain the form below (iam using bootstrap):
<form class="" action="coumysql.php" method="post" style="margin-left:100px;">
<input type="hidden" name="act" value="add"/>
<div class="form-group" >
<label class="control-label" for="course_id">Course Code:</label>
<div class="" >
<div class="col-xs-3">
<input type="text" class="form-control" id="email" placeholder="" name="course_id" required="">
</div>
</div>
</div> <br>
<br>
<div class="form-group">
<label class="control-label " for="course_name">Course Name:</label>
<div class="">
<div class="col-xs-3">
<input type="text" class="form-control" id="pwd" placeholder="" name="course_name" required="">
</div>
</div>
</div><br>
<br>
<div class="form-group" style="display: inline;">
<div class="col-sm-offset-1 "><br>
<button type="submit" class="btn btn-default">Add Subject</button>
</div>
</div>
</form>
the form processed at the page named coumysql.php
<?php
include 'connect.php';
if(isset($_POST['act'])){
if($_POST['act'] == 'add'){
if ($mysqli->query("INSERT INTO courses (course_id, course_name) VALUES ('".$_POST['course_id']."', '".$_POST['course_name']."');")) {
echo "data added";
}
}else if($_POST['act'] == 'delete'){
if ($mysqli->query("DELETE FROM courses WHERE course_id= ('".$_POST['course_id']."');")) {
echo "data deleted";
}
}
}
?>
i want the message "data added" or "data deleted" to be shown in courses.php after successfully form submitted to database
You could create a session() variable and pass it to the view. Like so:
<?php
include 'connect.php';
session_start();
if(isset($_POST['act'])){
if($_POST['act'] == 'add'){
if ($mysqli->query("INSERT INTO courses (course_id, course_name) VALUES ('".$_POST['course_id']."', '".$_POST['course_name']."');")) {
$_SESSION['insert']="Data has been successfully created!";
header('Location: courses.php');
}
}else if($_POST['act'] == 'delete'){
if ($mysqli->query("DELETE FROM courses WHERE course_id= ('".$_POST['course_id']."');")) {
$_SESSION['delete']="Data has been successfully deleted!";
header('Location: courses.php');
}
}
}
?>
Then catch them on courses.php like so:
<?php
session_start();
$added = $_SESSION['insert'];
$deleted=$_SESSION['delete'];
?>
<form class="" action="coumysql.php" method="post" style="margin-left:100px;">
<input type="hidden" name="act" value="add"/>
<div class="form-group" >
<label class="control-label" for="course_id">Course Code:</label>
<div class="" >
<div class="col-xs-3">
<input type="text" class="form-control" id="email" placeholder="" name="course_id" required="">
</div>
</div>
</div> <br>
<br>
<div class="form-group">
<label class="control-label " for="course_name">Course Name:</label>
<div class="">
<div class="col-xs-3">
<input type="text" class="form-control" id="pwd" placeholder="" name="course_name" required="">
</div>
</div>
</div><br>
<br>
<div class="form-group" style="display: inline;">
<div class="col-sm-offset-1 "><br>
<button type="submit" class="btn btn-default">Add Subject</button>
</div>
<?php
if(!empty($added)){
?>
<div class="alert aler-success"><p><?php echo $added;?></p></div>
<?php }elseif(!empty($deleted)){
?>
<div class="alert aler-success"><p><?php echo $deleted;?></p></div>
<?php
}?>
</div>
</form>
Note: u can customize div tag as u want..

Data wont insert into Database

I'm trying to insert data from a form to my database but it doesn't seem to work. I've put an echo after the insert query so I can verify that the data was inserted but it doesn't echo what I've written. Is there a problem with my query or any part of my php?
My PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "stat_system";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$fname = $lname = $mname = $contact = $age = $attain = $course = $school = $position = $exp = $ref = $batchtxt = $hiredate = $prevbpo = $remarks = $nho = $nonbpo = $holdAttain = $holdPos = "";
$error_flag = 0;
if (isset($_POST['submit'])) {
$holdAttain = (isset($_POST['cmbAttain']));
$holdPos = (isset($_POST['cmbPosition']));
if (!empty($_POST['firstname'])) {
$fname = $_POST['firstname'];
}
if (!empty($_POST['lastname'])) {
$lname = $_POST['lastname'];
}
if (!empty($_POST['middlename'])) {
$mname = $_POST['middlename'];
}
if (!empty($_POST['contact'])) {
$contact = $_POST['contact'];
}
if (!empty($_POST['age'])) {
$age = $_POST['age'];
}
if (isset($_POST['cmbAttain'])) {
$attain = $_POST['cmbAttain'];
}
if(isset($_POST['school'])) {
$school = $_POST['school'];
}
if(isset($_POST['course'])) {
$course = $_POST['course'];
}
if (isset($_POST['exp'])) {
$exp = $_POST['exp'];
}
if (!empty($_POST['remarks'])) {
$remarks = $_POST['remarks'];
}
if (isset($_POST['nonbpo'])) {
$nonbpo = $_POST['nonbpo'];
}
if (isset($_POST['prevbpo'])) {
$prevbpo = $_POST['prevbpo'];
}
if (!empty($_POST['ref'])) {
$ref = $_POST['ref'];
}
if (isset($_POST['hiredate'])) {
$hiredate = $_POST['hiredate'];
}
if (isset($_POST['batchtxt'])) {
$batchtxt = $_POST['batchtxt'];
}
if (!empty($_POST['nho'])) {
$nho = $_POST['nho'];
}
if($error_flag == 0){
$sql = mysqli_query($conn,"INSERT INTO applicants (appID, appLastName, appFirstName, appMidleName, Age, appPhoneNumber, appBatch, appExperience, appRemarks, appPreviousBPO, appSchool, appCourse, appGraduate, appNonBPO, appPosition, appHireDate, appNHO, appReferrer)
VALUES (NULL, '$lname', '$fname', '$mname', $age, '$contact', $batchtxt, '$exp', $remarks, '$school', '$course', '$attain', '$nonbpo', '$position', $hiredate, $nho, '$ref')");
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#succModal').modal('show');
});
</script>";
$fname = $lname = $mname = $contact = $age = $attain = $course = $school = $batchtxt = $ref = $hiredate = $position = $exp = $prevbpo = $remarks = $nho = $nonbpo = $holdAttain = $holdPos = "";
}
else {
print '<script type="text/javascript">';
print 'alert("Please fill in all the fields!")';
print '</script>';
}
}
mysqli_close($conn);
?>
My HTML:
<div id="addApplicant" class="addApp-marginleft" style="height:1000px">
<form id="registration" class="form-horizontal" method="post" action="index.php">
<div class="row">
<div align="center">
<h3>Add Applicant</h3>
<br>
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>First name:</small></label>
<div class="col-sm-4">
<input required type="text" name="firstname" autocomplete="off" placeholder="Firstname" id="firstname" class="form-control" value="<?php echo $fname;?>">
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small> Last name:</small></label>
<div class="col-sm-4">
<input required type="text" name="lastname" autocomplete="off" id="lastname" placeholder="Lastname" class="form-control" value="<?php echo $lname;?>">
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Middle name:</small></label>
<div class="col-sm-4">
<input required type="text" name="middlename" autocomplete="off" id="middlename" placeholder="middlename" class="form-control" value="<?php echo $mname;?>">
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Contact number:</small></label>
<span id="errmsg"></span>
<div class="col-sm-4">
<input required type="text" name="contactnum" autocomplete="off" onkeypress="return isNumber(event)" placeholder="Contact number" id="contact" class="form-control" maxlength="11" value="<?php echo $contact;?>"/>
</div>
<?php
echo '<script>';
echo 'function isNumber(evt) {';
echo 'evt = (evt) ? evt : window.event;';
echo 'var charCode = (evt.which) ? evt.which : evt.keyCode;';
echo 'if (charCode > 31 && (charCode < 48 || charCode > 57)) {';
echo 'return false;';
echo '}';
echo 'return true;';
echo '}';
echo '</script>';
?>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Age:</small></label>
<div class="col-sm-4">
<input required type="text" autocomplete="off" placeholder="age" name="age" id="age" class="form-control" value="<?php echo $age;?>">
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Graduate:</small></label>
<div class="col-sm-4">
<select required name="cmbAttain" id="cmbAttain" class="form-control" onChange="disableCmb();">
<option value="">Choose</option>
<option value="Yes" <?php if($holdAttain == "Yes") echo "selected"; ?>>Yes</option>
<option value="No" <?php if($holdAttain == "No") echo "selected"; ?>>No</option>
</select>
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>School:</small></label>
<div class="col-sm-4">
<input type="text" name="school" autocomplete="off" id="school" placeholder="School" class="form-control" value="<?php echo $school;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Course:</small></label>
<div class="col-sm-4">
<input type="text" name="course" autocomplete="off" id="course" placeholder="Course" class="form-control" value="<?php echo $course;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Batch:</small></label>
<div class="col-sm-4">
<input type="text" name="batchtxt" autocomplete="off" id="batchtxt" placeholder="Batch" class="form-control" value="<?php echo $batchtxt;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Experience:</small></label>
<div class="col-sm-4">
<input type="text" name="exp" autocomplete="off" id="exp" placeholder="Experience" class="form-control" value="<?php echo $exp;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Previous BPO:</small></label>
<div class="col-sm-4">
<input type="text" name="prevbpo" autocomplete="off" id="prevbpo" placeholder="Previous BPO" class="form-control" value="<?php echo $prevbpo;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Non-BPO:</small></label>
<div class="col-sm-4">
<input type="text" name="nonbpo" autocomplete="off" id="nonbpo" placeholder="Non-BPO" class="form-control" value="<?php echo $nonbpo;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Remarks:</small></label>
<div class="col-sm-4">
<input type="text" name="remarks" autocomplete="off" id="remarks" placeholder="Remarks" class="form-control" value="<?php echo $remarks;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Hire Date:</small></label>
<div class="col-sm-4">
<input type="date" name="hiredate" id="hiredate" class="form-control" autocomplete="off" value="<?php echo $hiredate;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Position:</small></label>
<div class="col-sm-4">
<select required name="cmbPosition" id="cmbPosition" class="form-control" data-size="5" >
<option selected value="">Choose</option>
<option value="Customer Service Representative" <?php if($holdPos == "Customer Service Representative") echo "selected"; ?>>Customer Service Representative</option>
<option value="Image Enhancer" <?php if($holdPos == "Image Enhancer") echo "selected"; ?>>Image Enhancer</option>
</select>
</div>
<div class="col-sm-4">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>NHO:</small></label>
<div class="col-sm-4">
<input type="date" name="nho" id="nho" class="form-control" autocomplete="off" value="<?php echo $nho;?>">
</div>
</div>
<div class="form-group" align="center" >
<label class="col-sm-4 control-label"><small>Referrer:</small></label>
<div class="col-sm-4">
<input type="text" name="ref" autocomplete="off" id="ref" placeholder="Name of Referrer" class="form-control" value="<?php echo $ref;?>">
</div>
</div>
<div class="form-group" align="center" >
<div class="col-sm-4">
</div>
<div class="col-sm-4">
<div class="btn-group " role="group" aria-label="...">
<input id="submitbtn" type="submit" name="submit" class="btn btn btn-success" value="Submit" data-target="#succModal">
<input type="reset" name="reset" class="btn btn-warning" value="Clear">
</div>
</div>
<div class="col-sm-4">
</div>
</div>
</form>
</div>
<div class="container">
<!-- Register Success Modal -->
<div class="modal fade" id="succModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body" align="center">
<p>REGISTRATION SUCCESSFUL</p>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
use $_POST instead of $_REQUEST..
like:
$lname = $_POST['lname'];
Just at a glance, you're NULL tests should be seperated by &&, not ||. The way you have it, it's only checking whether one (any) of them contain a value.
There is some errors with you query, just replace it with
$sql = "INSERT INTO applicants (appLastName, appFirstName, appMidleName, Age, appPhoneNumber, appBatch, appExperience, appRemarks, appPreviousBPO, appSchool, appCourse, appGraduate, appNonBpo, appPosition, appHireDate, appNHO, appReferrer) VALUES ('$lname','$fname','$mname',$age,'$con',$batch,'$exp','$rem','$prevbpo','$school','$course','$gradsit', '$nbpo', '$pos', '$hdate', '$nho', '$ref')";
here, there is no need to add appid as it is auto-incremented. Also there are some missing single quotes.
Skip to send value NULL in your insert statement
where you check whether $_POST is empty, if it is empty set $error_flag=1
Inside if (isset($_POST['submit'])) { print $_POST
Hope this will help to debug. If still issue, check your error_log

Categories