URL Rewrite issue after submit - php

I succesfully managed to add to my url an parameter but I can't increment it. For example, if I click on the submit button the url should transform from http://localhost/code/1 to http://localhost/code/2 . I have made an input hidden to access the url but I can't redirect it to the desired value, how can I do this? This is my PHP code:
<?php
$cod=strtoupper($_GET['params']);
$i=$_GET['params1'];
$id_rezervare="SELECT id FROM trezervare WHERE numar_rezervare = '$cod'";
$id_rezervare = $db->DbGetOne($id_rezervare);
$cod_rezervare="SELECT UPPER(numar_rezervare) FROM trezervare WHERE numar_rezervare = '$cod'";
$cod_rezervare = $db->DbGetOne($cod_rezervare);
$cod_rezervare1 = strtoupper($cod_rezervare);
$nr_camere="SELECT count(*) FROM trezervarecont WHERE idrezervare= $id_rezervare ";
$nr_camere = $db->DbGetOne($nr_camere);
$checkin_status=TRUE;
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$data_nasterii= $_GET['datanasterii'];
$test_arr = explode('/', $data_nasterii);
if(isset($_POST['trimite'])){
if (count($test_arr) == 3) {
if (checkdate($test_arr[0], $test_arr[1], $test_arr[2])) {
} else {
$message = "Date has an invalid format";
echo "<script type='text/javascript'>alert('$message');</script>";
}
} else {
$message = "No date selected";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
if(isset($_POST['trimite'])){
$i++;
}
?>
<div class="animated fadeOutZoom">
<div class="container container-sm animated fadeInDown">
<div class="center-block mt-xl">
<div class="panel">
<div class="panel-body">
<p class="pv text-bold">Check-in for room number <?php echo $i; ?></p>
<form action="" method="post">
<div class="row">
<div class="col-md-12 form-group">
<label for="nume">Nume</label>
<input type="text" id="text " class="form-control " name="nume" >
</div>
<input type="hidden" id="custId" name="checkin_status" value="<?php echo 1;?>">
<input type="text" id="custId" name="checkin_status" value="<?php echo $actual_link;?>">
<div class="col-md-12 form-group">
<label for="nume">Data Nasterii</label>
<input type="text" class="form-control" id="arrival_date" name="datanasterii"required/>
</div>
<div class="col-md-12 form-group">
<label for="nume">Locul nasterii</label>
<input type="text" id="text "class="form-control " name="loculnasterii" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Cetatenia</label>
<input type="text" id="text "class="form-control " name="cetatenie" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Localitate</label>
<input type="text" id="text "class="form-control " name="localitate" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Strada</label>
<input type="text" id="text "class="form-control " name="strada" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Numar strada</label>
<input type="text" id="text "class="form-control " name="nrstrada" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Tara</label>
<input type="text" id="text "class="form-control " name="tara" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Tip act</label>
<input type="text" id="text "class="form-control " name="tipact" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Serie act</label>
<input type="text" id="text "class="form-control " name="serieact" required>
</div>
<div class="col-md-12 form-group">
<label for="nume">Numar act</label>
<input type="text" id="text "class="form-control " name="nract" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="telefon">Telefon</label>
<input type="phone" id="telefon " class="form-control " name="telefon" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="email">Email</label>
<input type="email" id="email" class="form-control" name="email" required >
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<?php if($i==$nr_camere) echo'
<input type="submit" value="Finalizeaza rezervarea" class="btn btn-primary" name="trimite">';
elseif ($i>$nr_camere) {
header("location:../finalizeaza.php");
}
else echo ' <input type="submit" value="Continua rezervarea" class="btn btn-primary" name="trimite">';
?>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<script>
//$('#arrival_date, #departure_date').datepicker({format: 'yyyy/mm/dd'});
$('#arrival_date, #departure_date').datepicker({
format: 'yyyy-mm-dd',
endDate: '+0d',
minDate: '-120Y',
autoclose: true
});
</script>

Related

Adding an additional field breaks my query

When I add an additional field to my query, it fails. I have checked the spelling 20 or more times....I do not know what is wrong.. Please help!!
Working code BELOW
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
NOT WORKING CODE BELOW!
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
HERE IS A PICTURE OF MY DB SCHEMA
enter image description here
HERE IS THE TOTAL PHP FILE
<?php include_once "header.php";?>
<section class="content">
<div class="page-body clearfix">
<?php
$id=$_REQUEST['id'];
$sql=mysqli_query($db,"SELECT NMA_RAW.*, NMA_RAW.Check_Status, NMA_RAW.Resolved_Date, NMA_RAW.Filtered_Date FROM NMA_RAW WHERE (((NMA_RAW.Check_Status)='OK') AND ((NMA_RAW.Resolved_Date) Is Null) AND ((NMA_RAW.Filtered_Date) Is Null)) AND NMA_RAW.ID = $id;");
$row = mysqli_fetch_array($sql);
?>
<div class="panel panel-default">
<div class="panel-heading">NMA Active Ticket Form</div>
<div class="panel-body">
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-4">
<label>NMA System</label>
<input type="text" id="nma_system" class="form-control" placeholder="NMA System" value="<?= $row['NMA_System']; ?>" name="nmasystem">
</div>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?= $row['NMA_Ticket_Number']; ?>" name="nmaticketnum">
</div>
<div class="col-sm-4">
<label>Ticket Priority</label>
<input type="text" id="ticket_priority" class="form-control" placeholder="Ticket Priority" value="<?= $row['Tkt_Priority']; ?>" name="tktpriority">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Created On Worklist</label>
<input type="text" id="created_on_work_list" class="form-control" placeholder="Created On Worklist" value="<?= $row['Created_On_Worklist']; ?>" name="createdonworklist">
</div>
<div class="col-sm-4">
<label>Created Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="created_date" class="form-control" placeholder="Created Date" value="<?= $row['Create_Date']; ?>" name="createdate">
</div>
</div>
<div class="col-sm-4">
<label>Created time</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="time" id="created_time" class="form-control" placeholder="Created Time" value="<?= $row['Create_Time']; ?>" name="createtime">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Days Old</label>
<input type="text" id="days_old" class="form-control" placeholder="Days old" value="<?= $row['Days_Old']; ?>" name="daysold">
</div>
<div class="col-sm-4">
<label>Check</label>
<input type="text" id="check" class="form-control" placeholder="Check" value="<?= $row['Check_Status']; ?>" name="checkstatus">
</div>
<div class="col-sm-4">
<label>Ticket Status</label>
<input type="text" id="ticket_status" class="form-control" placeholder="Ticket Status" value="<?= $row['Ticket_Status']; ?>" name="ticketstatus">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Interval</label>
<input type="text" id="interval" class="form-control" placeholder="Interval" value="<?= $row['Interval_Onlist']; ?>" name="intervalonlist">
</div>
<div class="col-sm-4">
<label>Related Status</label>
<input type="text" id="relate_status" class="form-control" placeholder="Relate Status" value="<?= $row['Relate_Status']; ?>" name="relatestatus">
</div>
<div class="col-sm-4">
<label>WFA TR Num</label>
<input type="text" id="wfa_tr_num" class="form-control" placeholder="WF TR Num" value="<?= $row['WFA_TR_Num']; ?>" name="wfatrnum">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Recent WFA Dispatch Status</label>
<input type="text" id="recent_wfa_dispatch_status" class="form-control" placeholder="Recent WFA Dispatch Status"
value="<?= $row['Recent_WFA_Dispatch_Status']; ?>" name="recentwfadispatchstatus">
</div>
<div class="col-sm-4">
<label>Entity Status</label>
<input type="text" id="entity_status" class="form-control" placeholder="Intity Status" value="<?= $row['Entity_Status']; ?>" name="entitystatus">
</div>
<div class="col-sm-4">
<label>Entity</label>
<input type="text" name="entity" id="entity" class="form-control" placeholder="Entity" value="<?= $row['Entity']; ?>" name="entity">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Last Owner</label>
<input type="text" id="last_owner" class="form-control" placeholder="Last Owner" value="<?= $row['Last_Owner']; ?>" name="lastowner">
</div>
<div class="col-sm-4">
<label>First Cond Type</label>
<input type="text" id="first_cond_type" class="form-control" placeholder="First Cond Type" value="<?= $row['First_Cond_Type']; ?>" name="firstcondtype">
</div>
<div class="col-sm-4">
<label>Last Cond Type</label>
<input type="text" id="last_cond_type" class="form-control" placeholder="Last Cond Type" value="<?= $row['Last_Cond_Type']; ?>" name="lastcondtype">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>State</label>
<input type="text" id="state" class="form-control" placeholder="State" value="<?= $row['State']; ?>" name="st">
</div>
<div class="col-sm-4">
<label>Check Active</label>
<input type="text" id="check_active" class="form-control" placeholder="Check Active" value="<?= $row['Check_Active']; ?>" name="checkactive">
</div>
<div class="col-sm-4">
<label>Check Jepd</label>
<input type="text" name="check_jepd" id="check_jepd" class="form-control"placeholder="Check Jepd" value="<?= $row['Check_Jepd']; ?>" name="checkjepd">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>CLLI</label>
<input type="text" id="clli" class="form-control" placeholder="CLLI" value="<?= $row['CLLI']; ?>" name="clli">
</div>
<div class="col-sm-4">
<label>Resolved Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="resolved_date" class="form-control" placeholder="Resolved_Date" value="<?= $row['Resolved_Date']; ?>" name="resolved_date">
</div>
</div>
<div class="col-sm-4">
<label>Filtered Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="filtered_date" class="form-control" placeholder="Filtered Date" value="<?= $row['Filtered_Date']; ?>" name="filtereddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Filtered By</label>
<input type="text" id="filtered_by" class="form-control" placeholder="Filtered by" value="<?= $row['Filtered_By']; ?>" name="filteredby">
</div>
<div class="col-sm-4">
<label>Restored Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="restored_date" class="form-control" placeholder="Restored_Date" value="<?= $row['Restored_Date']; ?>" name="restoreddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 ">
<label class="text-bold"> NMA Comments subform </label>
</div>
<div class="col-sm-4">
</div>
</div>
<hr>
<div class="form-group">
<?php
$io = mysqli_query($db,"select * from NMA_Comments where NMA_Tkt_Num='$row[NMA_Ticket_Number]'");
$tr=mysqli_fetch_assoc($io);
?>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" name="NMA_Ticket_Number" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Tkt_Num']; ?>" >
</div>
<div class="col-sm-4">
<label>NMA Notes</label>
<textarea type="text" name="NMA_Notes" id="nma_notes" class="form-control" placeholder="NMA Notes"><?php echo $tr['NMA_Notes']; ?></textarea>
</div>
<div class="col-sm-4">
<label>NMA Note Date</label>
<input type="text" name="NMA_Ticket_Date" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Note_Date']; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<button class="btn btn-primary" name="UPDATE_RAW"> Save and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-success" name="MOVE_TO_RESOLVED"> Resolved and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger" name="MOVE_TO_INHIBITS"> Inhibit and Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
if(isset($_POST['UPDATE_RAW'])){
extract($_POST);
//print_r($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_INHIBITS'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Inhibited successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_RESOLVED'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Resolved successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php include_once "footer.php";?>
If the error you're getting is Incorrect date value: '' for column 15daytkt.nma_raw.Resolved_Date (as you've mentioned in the comments) :
It looks like you are passing an empty string to the Resolved_Date column, and it's invalid. Please make sure you're actually passing a valid date string in this format 2019-11-15. Usually, the HTML form inputs with the date type return this format.
You can verify this case by setting the value to NULL if it's empty. Try changing the query as below:
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem', Resolved_Date=NULLIF($resolved_date, '') WHERE ID='$id'");
Note the NULLIF($resolved_date, '') part. It will basically set the value to null if it is empty.
Hope it helps.

Cannot insert when clicking a button in Mysql using PHP

I am a beginner in web development, I used have an html elements, like textbox and other type of elements, I want to use them as my object and when they have a value and click a button, it will save the value of all the elements in mysql.
I have a code like this, but it cannot be inserted and anything does not happen when clicking a button.
Please help.
PHP:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'ytp');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(!$db ) {
die('Could not connect: ' . mysqli_error());
}
$fname = "";
$mname = "";
$lname = "";
$funame = "";
$cnum = "";
$bday = "";
$age = "";
$add = "";
if (isset($_POST['submit'])){
$fname = $_POST['fName'];
$mname = $_POST['mName'];
$lname = $_POST['lName'];
$funame = $_POST['fuName'];
$cnum = $_POST['Cnumber'];
$bday = $_POST['bday'];
$age = $_POST['age'];
$add = $_POST["address"];
}
$sql = "INSERT INTO employee ".
"(fName,mName,lName,fuName,cNumber,bDay,Age,Address) ".
"VALUES ('$fname','$mname','$lname','$funame','$cnum','$bday','$age','$add' )";
if (! mysqli_query($db , $sql)){
echo 'Cannot Insert';
}
else{
echo 'Success';
}
?>
HTML:
<div class="content">
<div class="row">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h5 class="title">Add User Information</h5>
</div>
<div class="card-body">
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</form>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</div>
</div>
</div>
</div>
Your HTML form is closing before submit button. You should close that after submit button and also need to manage hierarchy of opening form tag as below:
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="card-body">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</form>
Hope it helps you.
the form has been closed before the submit button.
the </form> tag should be placed after the <div class="card-footer">...</div>.
please try it. hope it will help.

Not displaying the error messages in PHP

If there are any errors while registration or login into the sit then it is not displaying the error message just printing the variable.Here is the code.Tried by doing echo as well but it is also not working.Tried with storing the result in a variable and displaying the message but still not worked.
<?php
include 'includes/db.php';
$match = '';
if(isset($_POST['submit_user']))
{
$email = $_POST['email'];
$check=mysqli_query($conn,"select * from users where user_email='$email'");
$checkrows=mysqli_num_rows($check);
if($checkrows>0)
{
$msg = "Email Already Exists";
header('Location:registration.php?msg=$msg');
}
else
{
if($_POST['password'] == $_POST['con_password'])
{
$ins_sql = "INSERT INTO users (first_name, last_name, user_email, user_password, username) VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[email]', '$_POST[password]', '$_POST[username]')";
$run_sql = mysqli_query($conn,$ins_sql);
}
else
{
$match = '<div class="alert alert-danger">Password doesn&apos;t match!</div>';
}
}
}
?>
<form class="form-horizontal" action="registration.php" method="post" role="form">
<div class="body">
<div class="row clearfix">
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="First Name" name="first_name" id="first_name" onkeypress="return checkSpcialChar(event)" required>
</div>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Last Name" name="last_name" id="last_name" required>
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Enter Your Email" name="email" id="email" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="password" class="form-control" placeholder="Password" name="password" id="password" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="type" class="form-control" placeholder="Confirm Password" name="con_password" id="con_password" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Enter Username" name="username" id="username">
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group drop-custum">
<select class="form-control show-tick" name="user_role" id="user_role" required>
<option value="">-- Select User role --</option>
<option value="admin">Admin</option>
<option value="employee">Employee</option>
</select>
</div>
</div>
<div class="col-sm-12">
<button type="submit" class="btn btn-raised g-bg-cyan" name="submit_user" id="subject">Submit</button>
<button type="submit" class="btn btn-raised">Cancel</button>
</div>
<span>
<?php if(isset($_GET['msg']))
echo $_GET['msg'];
?>
</span>
</div>
</div>
</form>

How to get bootstrap contact form working with php?

I want to add a contact form on my page but I've never worked with PHP before. I need help, please?
I'm working with the form below:
<a name="Contact"></a>
<div class="contact">
<div class="container">
<div class="row">
<div class="col-lg-8">
<h1 class="page-header text-center">Get in touch!</h1>
<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</form>
</div>
For for some reason, it's not displaying properly. This is how it looks:
screenshot of contact form

How can I send mail of complete form in php?

i am having a problem in sending mail to my server. i dont know why the problem is occurring? everything is done perfect but it is not working maybe the fields are not filling properly and alert message is also not shown
if(isset($_POST['uname']) && isset($_POST['fname']) && isset($_POST['nic']) && isset($_POST['pecno'])&& isset($_POST['quality[25]'])&& isset($_POST['bday'])&& isset($_POST['quality[26]'])&& isset($_POST['postal'])&& isset($_POST['cell'])&& isset($_POST['houseno'])&& isset($_POST['mail'])&& isset($_POST['city'])&& isset($_POST['province'])&& isset($_POST['country']) )
{
$_Name = $_POST['uname'];
$_Fname = $_POST['fname'];
$_NIC = $_POST['nic'];
$_Pecno = $_POST['pecno'];
$_Gender = $_POST['quality[25]'];
$_Bday = $_POST['bday'];
$_Qualification = $_POST['quality[26]'];
$_Postal = $_POST['postal'];
$_Cell = $_POST['cell'];
$_Houseno = $_POST['houseno'];
$_Email = $_POST['mail'];
$_City = $_POST['city'];
$_Province = $_POST['province'];
$_Country = $_POST['country'];
if(!empty($_Name) && !empty($_Fname) && !empty($_NIC) && !empty($_Pecno)&& !empty($_Gender)&& !empty($_Bday)&& !empty($_Qualification)&& !empty($_Postal)&& !empty($_Cell)&& !empty($_Houseno)&& !empty($_Email)&& !empty($_City)&& !empty($_Province)&& !empty($_Country))
{
$to = 'info#mymail.com';
$subject = 'Join us mail';
$body = 'Sender Name : '.$_Name."\n".'Sender Father Name : '.$_Fname."\n".'Sender NIC : '.$_NIC."\n".'Sender PEC Number : '.$_Pecno."\n".'Sender Gender : '.$_Gender."\n".'Sender Birthday : '.$_Bday."\n".'Sender Qualification : '.$_Qualification."\n".'Sender Postal Address : '.$_Postal."\n".'Sender Cell Number : '.$_Cell."\n".'Sender House Number : '.$_Houseno."\n".'Sender Email : '.$_Email."\n".'Sender City : '.$_City."\n".'Sender Province : '.$_Province."\n".'Sender Country : '.$_Country;
$header = 'From : '.$_Email;
if(#mail($to, $subject, $body, $header))
{
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}else
{
echo 'Please Try again in a few mints !';
}
}
}
html code
<form method="POST" action="index.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="uname" name="uname" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="fname" name="fname" placeholder="Father Name" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="nic" name="nic" placeholder="CNIC/Passport Number" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="pecno" name="pecno" placeholder="PEC Number" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="designation" name="designation" placeholder="Designation" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="organization" name="organization" placeholder="Organization" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Gender: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="1" /> Male
</label>
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="2" /> Female
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" type="text" onfocus="(this.type='date')" id="bday" name="bday" placeholder="Date of Birth" ><br>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Qualification: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="1" /> Bachelors In Engineering
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="2" /> Masters
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="3" /> PhD
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="postal" name="postal" placeholder="Postal Address" type="text" >
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="cell" name="cell" placeholder="Cell Number" type="tel" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="houseno" name="houseno" placeholder="House Number" type="tel" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="mail" name="mail" placeholder="Email Address" type="email" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="city" name="city" placeholder="City" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="province" name="province" placeholder="Province/State" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="country" name="country" placeholder="Country" type="text" required>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right " type="submit">Send</button>
</div>
</div>
</div>
replace #mail with mail
if(#mail($to, $subject, $body, $header))
enable error reporting
error_reporting(E_ALL);
Show last error with:
print_r(error_get_last());
and check php_error.log for a problem
phpinfo();
for checking if mail module is enabled in php.
If all pass, check /var/log/mail about the messages, here could be 1001 issues with network, server, firewall etc...
hope it helps.
As you mentioned that same code is working perfectly on other page so please check it by removing "#" from mail as adding this will hide all notices and it will display error as well. Also try to print mail body text before mail function.

Categories