Update and Delete using PHP and AJAX - php

This is my first ever database with AJAX. I'm really lost now, I don't know what to do next.
I already done in the part I can insert data in database and viewing it in website as well. Updating the data is not done yet and it can only fetch data from database in the fill up form but it won't able to insert it in database. Deleting data by row is also my problem.
<?php
$connect = mysqli_connect("localhost", "root", "", "test");
$query = "SELECT * FROM tbl_users ORDER BY id DESC";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Database</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<h3 class="jumbotron jumbotron-fluid" align="center">Registration Database</h3>
<div class="container" style="width:900px;">
<div class="table-responsive">
<div align="right">
<input type="button" data-toggle="modal" data-target="#add_data_Modal" value="Add User" class="btn btn-primary">
</input>
</div>
<br />
<div id="employee_table">
<br />
<table class="table table-bordered table-hover">
<tr class = thead-dark>
<th width="40%">First Name</th>
<th width="40%">Last Name</th>
<th width="5%">View</th>
<th width="5%">Update</th>
<th width="5">Delete</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr id="<?php echo $row['id'] ?>" >
<td data-target="firstname"><?php echo $row["firstname"]; ?></td>
<td data-target="lastname"><?php echo $row["lastname"]; ?></td>
<td>
<input type="button" name="view" value="View" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-sm view_data" >
</td>
<td>
<input type="button" name="update" value="Update" id="<?php echo $row["id"]; ?>" class="btn btn-success btn-sm update_data" >
<td>
<input type="button" name="delete" value="Delete" id="<?php echo $row["id"]; ?>" class="btn btn-danger btn-sm delete_data" >
</td>
<?php
}
?>
</table>
</div>
</div>
</div>
<br />
<button onclick="topFunction()" id="myBtn" title="Go to top" class="btn btn-block btn-secondary mx-auto d-block">Back to Top</button>
</body>
</html>
<div id="add_data_Modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add User to Database</h4>
</div>
<div class="modal-body">
<form method="post" id="insert_form" >
<label>Full Name</label>
<input type="text" name="firstname" id="firstname" class="form-control" placeholder="Enter First Name" />
<br />
<input type="text" name="middlename" id="middlename" class="form-control" placeholder="Enter Middle Name" />
<br />
<input type="text" name="lastname" id="lastname" class="form-control" placeholder="Enter Last Name" />
<br />
<label>Address</label>
<input type="text" name="street" id="street" class="form-control" placeholder="Street">
<br />
<input type="text" name="barangay" id="barangay" class="form-control" placeholder="Barangay">
<br />
<select name="city" class="form-control">
<option value="Caloocan">Caloocan</option>
<option value="Las Piñas‎">Las Piñas‎</option>
<option value="Makati">Makati</option>
<option value="Malabon">Malabon</option>
<option value="Mandaluyong">Mandaluyong</option>
<option value="Manila">Manila</option>
<option value="Marikina">Marikina</option>
<option value="Muntinlupa">Muntinlupa</option>
<option value="Navotas">Navotas</option>
<option value="Parañaque">Parañaque</option>
<option value="Pasay">Pasay</option>
<option value="Pasig">Pasig</option>
<option value="Quezon City">Quezon City</option>
<option value="San Juan">San Juan</option>
<option value="Taguig">Taguig</option>
<option value="Valenzuela">Valenzuela</option>
</select>
<br />
<input type="text" name="zipcode" id="zipcode" class="form-control" placeholder="Zip Code">
<br />
<label>Birth Date</label><br />
<input type="date" value="date" id="date" name="birthday" class="form-control" locked onblur="getAge();" placeholder="YYYY-MM-DD" />
<br />
<label for="age">Age</label><br />
<input type="text" id="age" name="age" value="" class="form-control" placeholder="Your Age" readonly>
<br />
<label>Gender</label><br />
<input type="radio" name="gender" value="male" > Male<br />
<input type="radio" name="gender" value="female"> Female<br />
<br />
<label>Contact Number</label>
<br />
<div class="input-group-append">
<span class="input-group-text">+63</span>
<input type="text" name="contactnumber" id="contactnumber" class="form-control" placeholder="919 123 4567 - sample pattern" maxlength="12">
<br />
</div>
<label>Parents Name</label>
<input type="text" name="fathername" id="fathername" class="form-control" placeholder="Father Name" />
<br />
<input type="text" name="mothername" id="mothername" class="form-control" placeholder="Mother Name" />
<br />
<input type="submit" name="insertbutton" id="insertbutton" value="SAVE" class="btn btn-success" />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="update_data_Modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Update User to Database</h4>
</div>
<div class="modal-body " id="update_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">User Details</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#insert_form',).on("submit", function(event){
event.preventDefault();
if($('#firstname').val() == "")
{
alert("First Name is required");
}
else if($('#middlename').val() == '')
{
alert("Middle Name is required");
}
else if($('#lastname').val() == '')
{
alert("Last Name is required");
}
else if($('#street').val() == '')
{
alert("Street is required");
}
else if($('#barangay').val() == '')
{
alert("Barangay is required");
}
else if($('#city').val() == '')
{
alert("City is required");
}
else if($('#zipcode').val() == '')
{
alert("Zip Code is required");
}
else if($('#birthday').val() == '')
{
alert("Birthday is required");
}
else if($('#age').val() == '')
{
alert("Age is required");
}
else if($('#gender').val() == '')
{
alert("Gender is required");
}
else if($('#contactnumber').val() == '')
{
alert("Contact Number is required");
}
else if($('#fathername').val() == '')
{
alert("Father Name is required");
}
else if($('#mothername').val() == '')
{
alert("Mother Name is required");
}
else
{
$.ajax({
url:"insert.php",
method:"POST",
data:$('#insert_form').serialize(),
beforeSend:function(){
$('#insertbutton').val("Inserting");
},
success:function(data){
$('#insert_form')[0].reset();
$('#add_data_Modal').modal('hide');
$('#employee_table').html(data);
}
});
}
});
$(document).on('click', '.view_data', function(){
//$('#dataModal').modal();
var employee_id = $(this).attr("id");
$.ajax({
url:"select.php",
method:"POST",
data:{employee_id:employee_id},
success:function(data){
$('#employee_detail').html(data);
$('#dataModal').modal('show');
}
});
});
});
$(document).on('click', '.update_data', function(){
//$('#dataModal').modal();
var employee_id = $(this).attr("id");
$.ajax({
url:"update.php",
method:"POST",
data:{employee_id:employee_id},
success:function(data){
$('#update_detail').html(data);
$('#update_data_Modal').modal('show');
}
});
});
function getAge(){
var birthday = document.getElementById('date').value;
birthday = new Date(birthday);
var today = new Date();
var age = Math.floor((today-birthday) / (365.25 * 24 * 60 * 60 * 1000));
document.getElementById('age').value=age;
}
var mybutton = document.getElementById("myBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
INSERT
<?php
$connect = mysqli_connect("localhost", "root", "", "test");
if(!empty($_POST))
{
$output = '';
$firstname = mysqli_real_escape_string($connect, $_POST["firstname"]);
$middlename = mysqli_real_escape_string($connect, $_POST["middlename"]);
$lastname = mysqli_real_escape_string($connect, $_POST["lastname"]);
$street = mysqli_real_escape_string($connect, $_POST["street"]);
$barangay = mysqli_real_escape_string($connect, $_POST["barangay"]);
$city = mysqli_real_escape_string($connect, $_POST["city"]);
$zipcode = mysqli_real_escape_string($connect, $_POST["zipcode"]);
$birthday = mysqli_real_escape_string($connect, $_POST["birthday"]);
$age = mysqli_real_escape_string($connect, $_POST["age"]);
$gender = mysqli_real_escape_string($connect, $_POST["gender"]);
$contactnumber = mysqli_real_escape_string($connect, $_POST["contactnumber"]);
$fathername = mysqli_real_escape_string($connect, $_POST["fathername"]);
$mothername = mysqli_real_escape_string($connect, $_POST["mothername"]);
$query = "INSERT INTO tbl_users(firstname, middlename, lastname, street, barangay, city, zipcode, birthday, age, gender, contactnumber, fathername, mothername) VALUES ('$firstname', '$middlename', '$lastname', '$street', '$barangay', '$city', '$zipcode','$birthday','$age','$gender','$contactnumber','$fathername','$mothername')";
if(mysqli_query($connect, $query))
{
$output .= '<div class="alert alert-success alert-dismissible fade show">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Success!</strong> User is added in the database.
</div>';
$select_query = "SELECT * FROM tbl_users ORDER BY id DESC";
$result = mysqli_query($connect, $select_query);
$output .= '
<table class="table table-bordered table-hover">
<tr class = thead-dark>
<th width="40%">First Name</th>
<th width="40%">Last Name</th>
<th width="5%">View</th>
<th width="5%">Update</th>
<th width="5">Delete</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>' . $row["firstname"] . '</td>
<td>' . $row["lastname"] . '</td>
<td><input type="button" name="view" value="View" id="' . $row["id"] . '" class="btn btn-info btn-sm view_data" /></td>
<td><input type="button" name="update" value="Update" id="' . $row["id"] . '" class="btn btn-success btn-sm update_data" ></td>
<td><input type="button" name="delete" value="Delete" id="' . $row["id"] . '" class="btn btn-danger btn-sm delete_data" ></td>
</tr>
';
}
$output .= '</table>';
}
echo $output;
}
?>
UPDATE
<?php
if(isset($_POST["employee_id"]))
{
$output = '';
$connect = mysqli_connect("localhost", "root", "", "test");
$query = "SELECT * FROM tbl_users WHERE id = '".$_POST["employee_id"]."'";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$output .= '
<form method="post" id="edit_form" >
<label>Full Name</label>
<input type="text" value='.$row["firstname"].' class="form-control" placeholder="First Name" readonly /> <br />
<input type="text" value='.$row["middlename"].' class="form-control" placeholder="Middle Name" readonly /> <br />
<input type="text" value='.$row["lastname"].' class="form-control" placeholder="Last Name" readonly /> <br />
<label>Address</label>
<input type="text" id="street" value='.$row["street"].' class="form-control" placeholder="Street" /> <br />
<input type="text" id="barangay" value='.$row["barangay"].' class="form-control" placeholder="Barangay" /> <br />
<select name="city" class="form-control">
<option value="Caloocan">Caloocan</option>
<option value="Las Piñas‎">Las Piñas‎</option>
<option value="Makati">Makati</option>
<option value="Malabon">Malabon</option>
<option value="Mandaluyong">Mandaluyong</option>
<option value="Manila">Manila</option>
<option value="Marikina">Marikina</option>
<option value="Muntinlupa">Muntinlupa</option>
<option value="Navotas">Navotas</option>
<option value="Parañaque">Parañaque</option>
<option value="Pasay">Pasay</option>
<option value="Pasig">Pasig</option>
<option value="Quezon City">Quezon City</option>
<option value="San Juan">San Juan</option>
<option value="Taguig">Taguig</option>
<option value="Valenzuela">Valenzuela</option>
</select><br />
<input type="text" value='.$row["zipcode"].' class="form-control" placeholder="Zip Code" /> <br />
<label>Birth Date</label>
<br />
<input type="date" value='.$row["birthday"].' class="form-control" readonly />
<br />
<label>Age</label>
<input type="text" value='.$row["age"].' class="form-control" readonly />
<label>Gender</label>
<input type="text" value='.$row["gender"].' class="form-control" readonly />
<br />
<label>Contact Number</label>
<input type="text" value='.$row["contactnumber"].' class="form-control" placeholder="919 123 4567 - sample pattern" maxlength="12"><br />
<label>Parents Name</label>
<input type="text" value='.$row["fathername"].' class="form-control" readonly />
<br />
<input type="text" value='.$row["mothername"].' class="form-control" readonly />
<br />
<button type="submit" id="update" class="btn btn-success">UPDATE1</button>
</form>
';
}
echo $output;
}
?>

Related

data is not inserted (in database ) for unknown reason in my website server

I was trying to convert a form of ajax insert, delete , edit system to my own . Its working nicely in localhost . But whenever I am trying to run these code in my website server , insertion is not working ( delete and edit is working ) . My codes are :
<div class="container box">
<h1 align="center">PHP PDO Ajax CRUD </h1>
<br />
<div class="table-responsive">
<br />
<div align="right">
<button type="button" id="add_button" data-toggle="modal" data-target="#userModal"
class="btn btn-info btn-lg">Add</button>
</div>
<br /><br />
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="10%">Image</th>
<th width="30%"> Name</th>
<th width="30%">Education</th>
<th width="10%">age</th>
<th width="10%">Edit</th>
<th width="10%">Delete</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
<div id="userModal" class="modal fade">
<div class="modal-dialog">
<form method="post" id="user_form" enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add User</h4>
</div>
<div class="modal-body">
<label>Enter First Name</label>
<input type="text" name="name" id="name" class="form-control" />
<br />
<label>Enter Last Name</label>
<input type="text" name="education" id="education" class="form-control" />
<br />
<label>Enter Last Name</label>
<input type="text" name="age" id="age" class="form-control" />
<br />
<label>Select User Image</label>
<input type="file" name="user_image" id="user_image" />
<span id="user_uploaded_image"></span>
</div>
<div class="modal-footer">
<input type="hidden" name="user_id" id="user_id" />
<input type="hidden" name="operation" id="operation" />
<input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('#add_button').click(function(){
$('#user_form')[0].reset();
$('.modal-title').text("Add User");
$('#action').val("Add");
$('#operation').val("Add");
$('#user_uploaded_image').html('');
});
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"fetch.php",
type:"POST"
},
"columnDefs":[
{
"targets":[0, 3, 4],
"orderable":false,
},
],
});
$(document).on('submit', '#user_form', function(event){
event.preventDefault();
var name= $('#name').val();
var education= $('#education').val();
var age= $('#age').val();
var extension = $('#user_image').val().split('.').pop().toLowerCase();
if(extension != '')
{
if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1)
{
alert("Invalid Image File");
$('#user_image').val('');
return false;
}
}
if(name!= '' && education!= '' && age!= '')
{
$.ajax({
url:"insert.php",
method:'POST',
data:new FormData(this),
contentType:false,
processData:false,
success:function(data)
{
alert(data);
$('#user_form')[0].reset();
$('#userModal').modal('hide');
dataTable.ajax.reload();
}
});
}
else
{
alert("Both Fields are Required");
}
});
the code in insert.php are : (I am just showing the code instead maintaining proper way of using brackets , so that we can be right at the point )
<?php
include('db.php');
include('function.php');
if(isset($_POST["operation"]))
{
if($_POST["operation"] == "Add")
{
$image = '';
if($_FILES["user_image"]["name"] != '')
{
$image = upload_image();
}
$statement = $connection->prepare("
INSERT INTO new_table (name, education, age, image)
VALUES (:name, :education, :age, :image)
");
$result = $statement->execute(
array(
':name' => $_POST["name"],
':education' => $_POST["education"],
':age' => $_POST["age"],
':image' => $image
)
);
if(!empty($result))
{
echo 'Data Inserted';
}
}
?>
The result after submission appears as bellow :
enter image description here
You're refering to $_POST['operation'] in your AJAX code but is has no value defined in HTML, try replacing :
<input type="hidden" name="operation" id="operation" />
<input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
by
<input type="hidden" name="operation" id="operation" value="Add" />
<input type="submit" name="action" id="action" class="btn btn-success" />

Insert Multiple Records from Form at Once

I have two dynamic multi-selector form fields and I am trying to insert all records from the form into the database at once. Once selector is for the district and another one is a listing of data elements. For every district, there should be a record for each data element. So, if someone selects 2 districts and 3 data elements, 6 records should be inserted into the database. I appreciate any help anyone can provide. Thanks.
Here is my form code:
<form method="post" action="process.php" enctype="multipart/form-
data">
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search" class="form-control" size="15"
multiple="multiple">
<?php
while(!$category->atEnd()) { //dyn select
?>
<option value="<?php echo($category-
>getColumnVal("data_elementID")); ?>"><?php echo($category-
>getColumnVal("element_name")); ?></option>
<?php
$category->moveNext();
} //dyn select
$category->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search_rightAll" class="btn btn-block"><i
class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search_rightSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search_leftSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search_leftAll" class="btn btn-block"><i
class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="data_elementID[]" id="search_to" class="form-control"
size="15" multiple="multiple">
</select>
</div>
</div>
<p> </p>
<h4>Please select the district(s) that use this resource that you
would like to assign these data elements to:</h4>
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search2" class="form-control" size="15"
multiple="multiple">
<?php
while(!$districts_selected->atEnd()) { //dyn select
?>
<option value="<?php echo($districts_selected-
>getColumnVal("districtID")); ?>"><?php echo($districts_selected-
>getColumnVal("district_name")); ?></option>
<?php
$districts_selected->moveNext();
} //dyn select
$districts_selected->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search2_rightAll" class="btn btn-block"><i
class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search2_rightSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search2_leftSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search2_leftAll" class="btn btn-block"><i
class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="districtID[]" id="search2_to" class="form-control"
size="15" multiple="multiple">
</select>
</div>
</div>
<?php
$wa_startindex = 0;
while(!$category->atEnd()) {
$wa_startindex = $category->Index;
?>
<input name="softwareID[]" type="hidden" multiple="multiple" value="
<?php echo $_GET['softwareID']; ?>">
<?php
$category->moveNext();
}
$category->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
<br><br>
<input type="image" src="images/save.png" name="submit" id="submit"
alt="Save" />
</form>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#search').multiselect({
search: {
left: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
right: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
},
fireSearch: function(value) {
return value.length > 3;
}
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#search2').multiselect({
search: {
left: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
right: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
},
fireSearch: function(value) {
return value.length > 3;
}
});
});
</script>
Here is my insert code:
<?php
$dbh = new PDO("mysql:host=$hostname;dbname=mspa",$user,$pass);
?>
<?php
$array =
array($_POST['districtID'], $_POST['softwareID'],
$_POST['data_elementID']);
// pdo example
$sql = 'INSERT INTO district_data_elements (districtID, softwareID,
data_elementID) VALUES (:value1, :value2, :value3)';
// $dbh is pdo connection
$insertTable = $dbh->prepare($sql);
$countArray = count($array);
$i = 0;
while ($i < $countArray) {
$insertTable->bindParam(':value1', $array[1][$i], PDO::PARAM_INT);
// if value is int
$insertTable->bindParam(':value2', $array[2][$i], PDO::PARAM_STR);
// if value is str
$insertTable->bindParam(':value3', $array[3][$i], PDO::PARAM_STR);
$insertTable->execute();
$i++;
}
?>

Pass php variable to html input type tag in php

In PHP, I need to pass a variable to a html input type tag. How can I pass this?
I have tried to pass the html tag id, but nothing is happening.
Here my mysql code:
include('db_connection.php');
if (isset($_POST['submit1'])) {
$skills = $_POST["skills"];
}
if (isset($_POST['submit1'])) {
$skills = $_POST["skills"];
//print_r($skills);die;
}
$sql ="SELECT * FROM `tbl_master_property` WHERE `name` ='$skills'";
$result=$conn->query($sql);
while( $row = $result->fetch_assoc() ) {
$project[] = $row;
}
foreach ($project as $value) {
$pg_address = $value['pg_address'];
$pg_type = $value['pg_type'];
$pg_owner = $value['pg_incharge_name'];
$pg_mobile = $value['pg_incharge_mobile'];
//print_r($pg_mobile);die;
}
Here my html code:
<div class="search">
<label>PG Name</label>
<input type="text" id="pgname" placeholder="Search by PG Name" name="pgname" list="locations" class="searchlocation" />
<button type="submit1" id ="submit1" class="searchButton">
<i class="fa fa-search searchButtonSearch"></i>
</button>
</div>
<script>
$(function() {
$( "#pgname" ).autocomplete({
source: "autocomplete.php"
});
});
</script>
<div class="col-lg-12 form-group">
<label>Address</label>
<input class="border col-lg-12" type="text" name= "address" value="<?php echo $value['pg_address']; ?>" required/>
</div>
<div class="col-lg-12 form-group">
<label>PG Owner Name</label>
<input class="border" type="text" name= "pg_owner" value="<?php echo $value['pg_owner ']; ?> required />
</div>
Does this work?
<?php
include('db_connection.php');
if (isset($_POST['submit1'])) {
$skills = $_POST["skills"];
}
$sql ="SELECT * FROM `tbl_master_property` WHERE `name` LIKE '%$skills%'";
$result=$conn->query($sql);
while( $row = $result->fetch_assoc() ) {
$project[] = $row;
}
?>
<form action="" method="post">
<div class="search">
<label>PG Name</label>
<input type="text" id="skills" placeholder="Search by PG Name" name="skills" list="locations" class="searchlocation" />
<button type="submit1" id ="submit1" class="searchButton">
<i class="fa fa-search searchButtonSearch">Search</i>
</button>
</div>
</form>
<?php
foreach ($project as $value) {
$pg_address = $value['pg_address'];
$pg_type = $value['pg_type'];
$pg_owner = $value['pg_incharge_name'];
$pg_mobile = $value['pg_incharge_mobile'];
//print_r($pg_mobile);die;
?>
<script>
$(function() {
$( "#pgname" ).autocomplete({
source: "autocomplete.php"
});
});
</script>
<div class="col-lg-12 form-group">
<label>Address</label>
<input class="border col-lg-12" type="text" name= "address" value="<?php echo #$value['pg_address']; ?>" required/>
</div>
<div class="col-lg-12 form-group">
<label>PG Owner Name</label>
<input class="border" type="text" name= "pg_owner" value="<?php echo #$value['pg_owner']; ?>" required/>
</div>
<?php } ?>
Check this out
<div class="search">
<label>PG Name</label>
<input type="text" id="pgname" placeholder="Search by PG Name" name="pgname" list="locations" class="searchlocation" />
<button type="submit1" id ="submit1" class="searchButton">
<i class="fa fa-search searchButtonSearch"></i>
</button>
</div>
<script>
$(function() {
$( "#pgname" ).autocomplete({
source: "autocomplete.php"
});
});
</script>
<div class="col-lg-12 form-group">
<label>Address</label>
<input class="border col-lg-12" type="text" name= "address" value="<?php if(isset( $pg_address)) echo $pg_address; ?>" required/>
</div>
<div class="col-lg-12 form-group">
<label>PG Owner Name</label>
<input class="border" type="text" name= "pg_owner" value="<?php if(isset( $pg_owner) )echo $pg_owner; ?> required />
</div>

using session data in PHP

I'm having a difficult time understanding the $_SESSION function in PHP. I'm building a multipage form and when it was a single form, everything worked as expected. Now I'm trying to figure out $_SESSION so that data from page1 carries to page2 for the submit.
So here is page 1:
<?php require_once("../tim/includes/validation_functions.php");
include("../tim/includes/session.php");
require_once("../tim/includes/variables.php");
include ("/testing/tim/obervation-upload.php");
?>
<?php
session_start(); // Session starts here.
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/testing/tim/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/testing/tim/bootstrap-theme.min.css">
<script type="text/javascript" src="/testing/tim/js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="/testing/tim/js/bootstrap.min.js"></script>
<title>Assessment Application</title>
</head>
<body>
<div>
<h2>3SP Assessment</h2>
<span id="error">
<!---- Initializing Session for errors --->
<?php
if (!empty($_SESSION['error'])) {
echo $_SESSION['error'];
unset($_SESSION['error']);
}
?>
</span>
<form class="form-horizontal" role="form" name="assessment" action="application_form.php" method="post">
<div class="form-group" style="margin-bottom:10px;">
<label for="company_name" class="col-lg-1 col-md-2 col-sm-4 control-label"><strong>Company name:</strong></label>
<div class="col-md-2"> <input type="text" id="company_name" name="company_name" class="form-control" required> </div>
<div class="clearfix"></div>
<label for="date" class="col-lg-1 col-md-2 col-sm-4 control-label"><strong>Date:</strong></label>
<div class="col-md-2"><input type="date" name="date" id="date" class="form-control" required> </div>
<div class="clearfix"></div>
<label for="rsm" class="col-lg-1 col-md-2 col-sm-4 control-label"><strong>Regional Sales Manager:</strong></label>
<div class="col-md-2"> <input type="text" name="rsm" id="rsm" class="form-control" required></div>
<div class="clearfix"></div>
<label for="agents" class="col-lg-1 col-md-2 col-sm-4 control-label"><strong>Agents:</strong> </label>
<div class="col-md-2"> <input type="text" name="agents" id="agents" class="form-control" required></div>
<div class="clearfix"></div>
<label for="distributor" class="col-lg-1 col-md-2 col-sm-4 control-label"><strong>Distributor:</strong> </label>
<div class="col-md-2"><input type="text" name="distributor" class="form-control" required></div>
</div>
<p style="margin-left:5px;"><input class="btn btn-danger" type="reset">
<input style="margin-left:10px;" class="btn btn-success" type="submit" value="Next" /></p>
</form>
<p class="pull-left"><a type="button" class="btn btn-default" href="http://us.pipglobal.com/en/" target="_blank">Cancel</a></p>
</div>
</body>
</html>
page 2:
<?php require_once("../tim/includes/validation_functions.php");
include("../tim/includes/session.php");
require_once("../tim/includes/variables.php");
include ("/testing/tim/obervation-upload.php");
?>
<?php
session_start();
foreach ($_POST as $key => $value) {
$_SESSION['post'][$key] = $value;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/testing/tim/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/testing/tim/bootstrap-theme.min.css">
<script type="text/javascript" src="/testing/tim/js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="/testing/tim/js/bootstrap.min.js"></script>
<title>Assessment Application</title>
</head>
<body>
<div>
<h2>3SP Assessment</h2>
<form name="assessment" action="create_new_record.php" method="POST" enctype="multipart/form-data">
<p>Department name: <input type="text" name="department_name" /> </p>
<p>Participant name: <input type="text" name="participant_name" /> </p>
<p>Activity performed: <textarea cols="25" rows="3" name="activity" ></textarea> </p>
<p>Location: <input type="text" name="location" /> </p>
<p>Conditon: <select class="form-control" name="condition" style="width:20%;">
<option value="dry" id="dry">Dry</option>
<option value="heavy_oil" id="heavy_oil">Heavy Oil/Grease</option>
<option value="light_oil" id="light_oil">Light Oil</option>
<option value="sandy" id="sandy">Sandy/Grit</option>
<option value="wet" id="wet">Slightly Wet</option>
</select></p>
<div class="well">
<p>Avg Number of Recordable Injuries:
<input type="number" name="injuries" />
<select name="injury_time_frame">
<option value="last month">Last month</option>
<option value="last 6 months">Last 6 months</option>
<option value="last 12 months">Last 12 months</option>
</select>
</p>
<h4>Based on the number of Recordable Injuries - Estimate the Injury Type by Percentage </h4>
<div class="container-fluid">
<div class="form-group row">
<div class="col-md-3 col-sm-4"><input class="form-control" id="cuts" name="cuts" type="number" min="0" max="100" value="" placeholder="Cuts / Lacerations / Abrasion" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="burns" name="burns" type="number" min="0" max="100" value="" placeholder="Heat or Chemical Burn" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="infection" name="infection" type="number" min="0" max="100" value="" placeholder="Infection" /> </div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="dermatitis" name="dermatitis" type="number" min="0" max="100" value="" placeholder="Dermatitis" /> </div>
<div class="clearfix visible-xs-block"></div> <div class="hidden-xs hidden-sm"><br /><br /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="puncture" name="puncture" type="number" min="0" max="100" value="" placeholder="Puncture" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="sprain" name="sprain" type="number" min="0" max="100" value="" placeholder="Carpal Tunnel / Sprain" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" id="impact" name="impact" type="number" min="0" max="100" value="" placeholder="Impact / Contusion / Inflammation" /> </div>
</div>
</div>
<p id="rec_injuries"></p>
<script>
function percentageTest() {
// Get the value of the input fields
a = document.getElementById("cuts").value;
b = document.getElementById("burns").value;
c = document.getElementById("infection").value;
d = document.getElementById("dermatitis").value;
e = document.getElementById("puncture").value;
f = document.getElementById("sprain").value;
g = document.getElementById("impact").value;
var x = (a + b + c + d + e + f + g);
// grouping together and doing the math
if (x = !100) {
text = "The total percentage must equal 100%";
} else {
text = "Congrats the total = 100%";
}
document.getElementById("rec_injuries").innerHTML = text;
}
</script>
</div>
<div class="well">
<p>Avg Number of Non-recordable Injuries: <input type="number" name="non_rec_injuries" />
<select name="non_rec_injury_timeframe">
<option value="last month">Last month</option>
<option value="last 6 months">Last 6 months</option>
<option value="last 12 months">Last 12 months</option>
</select>
</p>
<h4>Based on the number of Non-recordable Injuries - Estimate the Injury Type by Percentage </h4>
<div class="container-fluid">
<div class="form-group row">
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_cuts" type="number" min="0" max="100" value="" placeholder="Cuts / Lacerations / Abrasion" /> </div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_burns" type="number" min="0" max="100" value="" placeholder="Heat or Chemical Burn" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_infection" type="number" min="0" max="100" value="" placeholder="Infection" /> </div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_dermatitis" type="number" min="0" max="100" value="" placeholder="Dermatitis" /> </div>
<div class="clearfix visible-xs-block"></div> <div class="hidden-xs hidden-sm"><br /><br /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_puncture" type="number" min="0" max="100" value="" placeholder="Puncture" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_sprain" type="number" min="0" max="100" value="" placeholder="Carpal Tunnel / Sprain" /></div>
<div class="col-md-3 col-sm-4"><input class="form-control" name="non_rec_impact" type="number" min="0" max="100" value="" placeholder="Impact / Contusion / Inflammation" />
</div>
</div>
</div>
</div>
<p>Estimated Cost of Productivity (Downtime)/minute: $ <input type="number" name="cost_of_productivity" /> </p>
<p>Percent of leakage related to uncontrolled dispensing: <input type="number" min="0" max="100" name="leakage" /> % </p>
<p>Which competitor is the participant using? <input type="text" name="competitor" /></p>
<p>Usage Rate per 12 months (pairs): <input type="number" min="0" name="usage_rate" /></p>
<p>Estimated cost per pair: $ <input type="number" min="0" name="cost_per_pair" /></p>
<br />
<div class="container" style="margin-left:0px; padding-left:0px;">
<div class="form-group row" style="margin-left:0px;">
<div class="col-md-3 col-sm-6">
<label for="safetyHazard1_notes"><strong>Safety observation 1:</strong></label> <input type="file" name="safetyHazard1" id="safetyHazard1" value=""><br /> <br />
<textarea cols="25" rows="3" id="safetyHazard1_notes" name="safetyHazard1_notes" placeholder="Enter notes for this observation" ></textarea> </div>
<div class="col-md-3 col-sm-6">
<label for="safetyHazard2_notes"><strong>Safety observation 2:</strong></label> <input type="file" name="safetyHazard2" id="safetyHazard2" value=""><br /><br />
<textarea cols="25" rows="3" id="safetyHazard2_notes" name="safetyHazard2_notes" placeholder="Enter notes for this observation" ></textarea> </div>
<div class="col-md-3 col-sm-6">
<label for="safetyHazard3_notes"><strong>Safety observation 3:</strong></label> <input type="file" name="safetyHazard3" id="safetyHazard3" value=""><br /><br />
<textarea cols="25" rows="3" id="safetyHazard2_notes" name="safetyHazard2_notes" placeholder="Enter notes for this observation" ></textarea> </div>
<div class="col-md-3 col-sm-6">
<label for="other_notes"><strong>Other observations:</strong></label> <input type="file" name="otherObservation" id="otherObservation" value=""><br /><br />
<textarea cols="25" rows="3" id="other_notes" name="other_notes" placeholder="Enter notes for this observation" ></textarea> </div>
</div></div>
<br />
<p style="margin-left:5px;"><input class="btn btn-danger" type="reset">
<input style="margin-left:10px;" class="btn btn-primary" type="button" name="new_location" value="Add Additional Location" />
<input style="margin-left:10px;" class="btn btn-success" type="submit" name="submit" value="Create New Assessment" /></p>
</form>
<p class="pull-left"><a type="button" class="btn btn-default" href="http://us.pipglobal.com/en/" target="_blank">Cancel</a></p>
</div>
</body>
</html>
And finally the processing page:
<?php
require_once("../tim/includes/session.php");
require_once ("../tim/includes/functions.php");
require_once("../tim/includes/validation_functions.php");
?>
<?php
if(isset($_POST["submit"])) {
$target_dir = $_SERVER['DOCUMENT_ROOT'] . '/testing/tim/uploads/';
$target_file = $target_dir . basename($_FILES["safetyHazard1"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["safetyHazard1"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["safetyHazard1"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["safetyHazard1"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["safetyHazard1"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
foreach ($_POST as $key => $value) {
$_SESSION['post'][$key] = $value;
}
extract($_SESSION['post']);
// Process the form
$department_name = ($_POST['department_name']);
$participant_name = ($_POST['participant_name']);
$activity = ($_POST['activity']);
$location = ($_POST['location']);
$rec_injuries = ($_POST['injuries']);
$rec_injuries_timeframe = ($_POST['injury_time_frame']);
$non_rec_injuries = ($_POST['non_rec_injuries']);
$non_rec_injuries_timeframe = ($_POST['non_rec_injury_timeframe']);
$rec_cuts = ($_POST['cuts']);
$rec_burns = ($_POST['burns']);
$rec_infection = ($_POST['infection']);
$rec_dermatitis = ($_POST['dermatitis']);
$rec_puncture = ($_POST['puncture']);
$rec_sprain = ($_POST['sprain']);
$rec_impact = ($_POST['impact']);
$non_rec_cuts = ($_POST['non_rec_cuts']);
$non_rec_burns = ($_POST['non_rec_burns']);
$non_rec_infection = ($_POST['non_rec_infection']);
$non_rec_dermatitis = ($_POST['non_rec_dermatitis']);
$non_rec_puncture = ($_POST['non_rec_puncture']);
$non_rec_sprain = ($_POST['non_rec_sprain']);
$non_rec_impact = ($_POST['non_rec_impact']);
$cost_of_productivity = ($_POST['cost_of_productivity']);
$leakage = (($_POST['leakage']) / 100);
$usage_rate = ($_POST['usage_rate']);
$cost_per_pair = ($_POST['cost_per_pair']);
$condition = ($_POST['condition']);
$safety_hazard_1 = basename( $_FILES["safetyHazard1"]["name"]);
$safety_hazard_2 = ($_POST['safetyHazard2']);
$safety_hazard_3 = ($_POST['safetyHazard3']);
$other_observation = ($_POST['otherObservation']);
$safetyHazard1_notes = ($_POST['safetyHazard1_notes']);
$safetyHazard2_notes = ($_POST['safetyHazard2_notes']);
$safetyHazard3_notes = ($_POST['safetyHazard3_notes']);
$otherNotes = ($_POST['otherNotes']);
$competitor = ($_POST['competitor']);
$company_name = ($_POST['company_name']);
$date = ($_POST['date']);
$rsm = ($_POST['rsm']);
$agents = ($_POST['agents']);
$distributor = ($_POST['distributor']);
print "distributor: " . $distributor;
exit;
// Perform first database insert
$query1 = "INSERT INTO location_info (";
$query1 .= "`department`, `participant`, `activity`, `location`, `rec_injuries`, `rec_injuries_timeframe`, `non_rec_injuries`, `non_rec_injuries_timeframe`, `competitor`, `cost_per_pair`, `usage_rate`, `leakage`, `cost_of_productivity`, `non_rec_impact`, `non_rec_sprain`, `non_rec_puncture`, `non_rec_dermatitis`, `non_rec_infection`, `non_rec_burns`, `non_rec_cuts`, `rec_impact`, `rec_sprain`, `rec_puncture`, `rec_dermatitis`, `rec_infection`, `rec_burns`, `rec_cuts`, `condition`, `safety_hazard_1`, `safety_hazard_2`, `safety_hazard_3`, `other_observation`,`safetyHazard1_notes`, `safetyHazard2_notes`, `safetyHazard3_notes`, `otherNotes`";
$query1 .= ") VALUES (";
$query1 .= " '{$department_name}', '{$participant_name}', '{$activity}', '{$location}', '{$rec_injuries}', '{$rec_injuries_timeframe}',
'{$non_rec_injuries}', '{$non_rec_injuries_timeframe}', '{$competitor}', '{$cost_per_pair}', '{$usage_rate}', '{$leakage}', '{$cost_of_productivity}', '{$non_rec_impact}', '{$non_rec_sprain}', '{$non_rec_puncture}', '{$non_rec_dermatitis}', '{$non_rec_infection}', '{$non_rec_burns}', '{$non_rec_cuts}', '{$rec_impact}', '{$rec_sprain}', '{$rec_puncture}', '{$rec_dermatitis}', '{$rec_infection}', '{$rec_burns}', '{$rec_cuts}', '{$condition}', '{$safety_hazard_1}', '{$safety_hazard_2}', '{$safety_hazard_3}', '{$other_observation}','{$safetyHazard1_notes}', '{$safetyHazard2_notes}', '{$safetyHazard3_notes}', '{$otherNotes}'";
$query1 .= ")";
$result1 = mysqli_query($connection, $query1);
if ($result1) {
// Success
$_SESSION["message"] = "Assessment created.";
redirect_to("results.php");
} else {
// Failure
$_SESSION["message"] = "Assessment creation failed.";
redirect_to("errors.php");
}
// Perform second database insert
$query2 = "INSERT INTO general_assessment (";
$query2 .= "`company_name`, `date`, `rsm`, `agents`, `distributor`";
$query2 .= ") VALUES (";
$query2 .= " '{$company_name}', '{$date}', '{$rsm}', '{$agents}', '{$distributor}'";
$query2 .= ")";
$result2 = mysqli_query($connection, $query2);
if ($result2) {
// Success
$_SESSION["message"] = "Assessment created.";
redirect_to("results.php");
} else {
// Failure
$_SESSION["message"] = "Assessment creation failed.";
redirect_to("errors.php");
}
}
else {
redirect_to($_SERVER["DOCUMENT_ROOT"]."/testing/tim/errors-inserting.php");
}
?>
<?php
if (isset($connection)) { mysqli_close($connection); }
?>
You'll see on the processing page my little test of
print "distributor: " . $distributor;
exit;
this would obviously be removed when working.
Ok I think I've figured this out. I needed to "recall" the session data when I move to page 2.
So on the top of page 2 the code became:
<?php
session_start();
//store the posted values in the session variables
$_SESSION['company_name'] = $_POST['company_name'];
$_SESSION['date'] = $_POST['date'];
$_SESSION['rsm'] = $_POST['rsm'];
$_SESSION['agents'] = $_POST['agents'];
$_SESSION['distributor'] = $_POST['distributor'];
?>
You have to use line session_start(); on every page that you want to use the session - as the first line on top of the file.
You can set variables:
$_SESSION['username'] = "user";
and then retrieve them:
echo $_SESSION['username'];
You can then use session_destroy() to remove the saved session
To use a session variables for PHP at the many files. Try like this :
page1.php
<?php
session_start();
$_SESSION['name'] = 'Example session';
?>
When you use the session variables at the another page :
page2.php
<?php
include 'page1.php';
echo $_SESSION['name']; //Example session
?>
And to destroy session. Use session_destroy(); unset($_SESSION);

Submit INPUT to the database to return as a Table PHP jQuery MySQL

I'm trying to refresh a data input into an INPUT through a form and then SUBMIT this to the database to return it as a table on the same page. I want it to do this without showing the refresh of the page.
This is what I have currently. When I put data into any of the INPUT fields and click SUBMIT nothing happens and nothing shows for an error.
<?php
session_start();
error_reporting (E_ALL);
require '../core/cnn.php';
if(isset($_POST['submitsearchprojno'])) {
$searchprojno = $_POST["searchprojno"];
}
if(isset($_POST['submitsearchadd'])) {
$searchaddress = $_POST["searchaddress"];
}
if(isset($_POST['submitsearchpc'])) {
$searchpostcode = $_POST["searchpostcode"];
}
$searchpostcode = mysql_real_escape_string($searchpostcode);
$searchaddress = mysql_real_escape_string($searchaddress);
$searchprojno = mysql_real_escape_string($searchprojno);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Search Projects</h4>
</div>
<div class="modal-body">
<form class="modal-form" id="searchform" name="searchform" action="" method="post">
<div class="form-group">
<label class="col-md-4 control-label">Project Number</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchprojno" id="searchprojno" placeholder="Enter Project Number">
</div>
<button type="submit" class="btn blue" id="submitsearchprojno" name="submitsearchprojno" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchaddress" id="searchaddress" placeholder="Enter Address">
</div>
<button type="submit" class="btn blue" id="submitsearchadd" name="submitsearchadd" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Postcode</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchpostcode" id="searchpostcode" placeholder="Enter Postcode">
</div>
<button type="submit" class="btn blue" id="submitsearchpc" name="submitsearchpc" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-advance table-hover">
<thead>
<tr>
<th class="col-md-9"><i class="fa fa-list-alt"></i> Address</th>
<th class="col-md-3"></th>
</tr>
</thead>
<tbody>
<tr>
<?php $searchrs = mysql_query("SELECT ProjectNo, CONCAT(COALESCE(HouseNoName, ''), ' ', COALESCE(StreetName, ''), ' ',
COALESCE(TownOrCity, ''), ' ', COALESCE(Postcode, '')) AS Display, PropID, AreaID, AWGMember, Householder, HouseNoName,
StreetName, TownOrCity, Postcode, ContactTelephone, AlternatePhone, Email, PropertyTenure, PropertyNotes
FROM prop_property
WHERE IsActive = 1
AND (Postcode = '".$searchpostcode."'
OR StreetName = '".$searchaddress."'
OR ProjectNo = '".$searchprojno."')
") or die(mysql_error());
$checkrs = mysql_query("SELECT * FROM prop_property WHERE IsActive = 0");
if(!mysql_num_rows($checkrs) > 0) {
echo '<td> No record found!</td><td></td>';
}
else {
while ($results = mysql_fetch_array($searchrs)) {
echo '
<td id="displayadd">'.$results['Display'].'</td>
<td>
<form action="../jobdetails.php" method="post">
<input type="hidden" name="searchhouse" value=" '.$results['HouseNoName'].'" >
<input type="hidden" name="searchstreet" value=" '.$results['StreetName'].'" >
<input type="hidden" name="searchtown" value=" '.$results['TownOrCity'].'" >
<input type="hidden" name="searchpostcode" value=" '.$results['Postcode'].'" >
<input type="hidden" name="searchpropid" value=" '.$results['PropID'].'" >
<input type="hidden" name="searchprojectno" value=" '.$results['ProjectNo'].'" >
<button type="submit" class="btn default btn-xs blue-stripe" id="viewsearch" name="viewsearch">View Address</button>
</form>
</td>';
}
}?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</form>
<div class="modal-footer right">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
</div>
<script type="text/javascript">
$(function(){
$('#searchform').on('submit', function(e){
e.preventDefault();
//alert($('#searchpostcode').val())
$.post('includes/jobdetailssearch.php',
$('#searchform').serialize(),
function(data, status){
$('.table-responsive #displayadd').html(data.Display);
//$("#table-responsive td").last().append(data);
console.log("done");
}).fail(function () {
console.log("fail");
});
});
});
</script>
How can I get it to POST the INPUT to the database and return in the table?

Categories