php foreach loop editing wrong record in DB - php

Good day,
I've ran into a bit of a problem with my website.
I have a form which pulls a full table from my DB. Beside each record I have an 'Edit' and 'Remove' button (see image 1).
image 1
If I click on the edit button beside record 'Delete me', a modal appears and populates the value of each editable field with the current data available, and I can then edit each value and update the database. This works fine.
The problem I have; when I select one of the records where the 'Name' field is duplicated with a different 'Filling/Size' (for example, if I select 'Filling/Size' 5) it always updates and pre-populates the modal with the data from the first record in the table that shares the same 'Name'. Image 2 shows me clicking the 'Edit' button for record 1-5.
image 2
I've tried creating a foreach loop inside my foreach loop but that just duplicated every record many many times. My code is below. Any input or suggestions would be greatly appreciated.
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-table"></i>Items</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" name="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Filling/Size</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Edit/Remove</th>
</tr>
</tfoot>
<tbody>
<?php foreach ($result as $i => $row) { ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->filling; ?></td>
<td><?php echo $row->category; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->price; ?></td>
<td id="editRemoveButtonsCell">
<button id="editButton" type="button" class="btn btn-outline-success" data-toggle="modal" data-target="#editItemModal<?php echo $row->name;?>">Edit</button>
<button id="removeButton" type="button" class="btn btn-outline-danger" data-toggle="modal" data-target="#removeItemModal<?php echo $row->name;?>">Remove</button></td>
</tr>
<!-- Delete Modal -->
<div class="modal" id="removeItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Delete Item <?php echo $row->name?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Are you sure you want to delete item <?php echo $row->name?> <?php echo $row->filling;?>? <b>This cannot be undone!</b>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<input type="hidden" value="<?php echo $row->name;?>" name="deleteItemName" id="deleteItemName">
<input type="hidden" value="<?php echo $row->filling;?>" name="deleteItemFilling" id="deleteItemFilling">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="deleteItem" id="deleteItem" value="Delete" class="btn btn-danger" />
</div>
</div>
</form>
</div>
</div>
<!-- Edit Modal -->
<div class="modal" id="editItemModal<?php echo $row->name;?>" name="editItemModal<?php echo $row->name;?>">
<div class="modal-dialog">
<form>
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Edit Item <?php echo $row->name;?></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="form-group">
<label for="itemNameUpdate">Name</label>
<input type="text" class="form-control" id="itemNameUpdate" name="itemNameUpdate" placeholder="Enter Item Name" value="<?php echo $row->name;?>">
<input type="hidden" value="<?php echo $row->name;?>" name="itemNameOriginal" id="itemNameOriginal">
<input type="hidden" value="<?php echo $row->filling;?>" name="itemFillingOriginal" id="itemFillingOriginal">
</div>
<div class="form-group">
<label for="itemFillingUpdate">Filling/Size</label>
<input type="text" class="form-control" id="itemFillingUpdate" name="itemFillingUpdate" placeholder="Enter Filling/Size" value="<?php echo $row->filling;?>">
</div>
<div class="form-group">
<label for="itemCategoryUpdate">Category</label>
<select class="form-control" id="itemCategoryUpdate" name="itemCategoryUpdate">
<?php echo '<option>'.$row->category.'</option>';?>
<?php foreach($categories as $category) {echo '<option>'.$category->name.'</option>';}?>
</select>
</div>
<div class="form-group">
<label for="itemDescriptionUpdate">Description</label>
<textarea class="form-control" id="itemDescriptionUpdate" name="itemDescriptionUpdate" rows="3" placeholder="Item description (optional)"><?php echo $row->description;?></textarea>
</div>
<div class="form-group">
<label for="itemPriceUpdate">Price</label>
<input type="text" class="form-control" id="itemPriceUpdate" name="itemPriceUpdate" placeholder="Enter Price" value="<?php echo $row->price;?>">
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-cancel" data-dismiss="modal">Close</button>
<input type="submit" name="editItem" id="editItem" value="Edit" class="btn btn-success" />
</div>
</div>
</form>
</div>
</div>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="card-footer small text-muted">Use the navigation bar to the left to edit the menu.</div>
</div>
</div>

All your code references are to $row->name and I would judge it to be bad practise to reference anything in the code by name. You want to be idenitifying by a unique identifier (typically a number) on each case. So you don't get this sort of ambiguity.
Image 2 shows me clicking the 'Edit' button for record 1-5.
You can't event clearly identify your own rows in this question, without needing to pull in outside data that is only co-incidentally different.
What you want is a unique identifier for each row of your database table.
This is something that is an absolute basic standard and can be read in the MySQL Dev Tutorial Here.
This SO question may also be helpful to you.
So you can update your MySQL (assuming that's your database):
ALTER TABLE users ADD uid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
ADD INDEX (uid);
(also please see here as to which int type is best for your situation)
Once you have a unique identifier for each row, you need to then use that identifier on your code so, for example :
<input type="hidden" value="<?php echo $row->uid;?>"
name="deleteItemUniqueId" id="deleteItemUniqueId">
And
<div class="modal" id="editItemModal<?php echo $row->uid;?>"
name="editItemModal<?php echo $row->uid;?>">
And similarly apply this to your codebase throughout.
This stops any repetition of HTML ids and stops the code logic having issues with any ambiguity on the part of the identifying data given.

Related

How do I pass ID value of table in modal

I want to pass the id value of student in the modal form. When I clicked the button 1stgrade, here is my table code:
<tbody>
<?php
require_once '../dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM userinfo WHERE role='student' AND gradelvl='7' AND sectionname='$_POST[table7]' ORDER BY lrnno ASC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['fname']; ?></td>
and this is my modal form:
<td>
<div align="center">
<form action="studentprofilegradeaction.php" method="POST" class="form-horizontal">
<input type='text' name='id' value='<?php echo $row['id']; ?>' />
<!-- Button HTML (to Trigger Modal) -->
<i class="fa fa-building"></i>1st
<!-- Modal HTML -->
<div id="1stgrade7" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<input type='text' value='<?php echo $row['id'] ?>' />
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="modal-title">Please Fill Correctly</h2>
</div>
<div class="modal-header">
<h4 class="modal-title">1st Grading Result </h4>
</div>
<div class="modal-body">
<div align="left">
<b>Filipino:</b>
<input type="text" class="form-control" name="c71stgfilipino" >
</div>
I want to pass the id number to modal 1stgrade.
Replace your anchor tag:
<i class="fa fa-building"></i>1st
=>
<a id="openModal" data-id="<?php echo $row['id']; ?>" class="btn btn-info"><i class="fa fa-building"></i>1st</a>
Remove other unnecessary code from your while loop, keep modal code outside the loop and give id to your id input inside modal:
<input id="userId" type='text' value='<?php echo $row['id'] ?>' />
Then you need jquery to read the od of clicked row and set it to modal write this after :
<script>
$(document).ready(function() {
$("#openModal").click(function() {
//remove previous value
$("#userId").val("");
//this ll set id to your modal input
$("#userId").val($(this).attr("data-id"));
//open the modal
$("#1stgrade7").modal("show");
});
});
</script>

pass a value from mysql db to bootstrap modal

i'm new to core php coding here i'm having doubt in calling a db value to bootstrap modal popup
<td class="bgimg"><?php echo $obj["service_name"]; ?></td>
this is a line used in my code to send "service_id" which from a table and it should be displayed in the modal popup, from there, user has to fill the text fields and it should be update to another table with the same id.
here is the code of modal popup
<div id="edit-modal" class = "modal fade" tabindex="-1" role="dialog" style="padding-top: 150px;" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="myModalLabel">Choose your slots</h4>
</div>
<div class="modal-body">
<p class="edit-content">service id:</p>
<form role="form1" name="loginform" method="post" class="login-form">
<div class="form-group">
<table align="center">
<tr>
<td colspan="2"><center>slot 1</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot1_dt"> </td>
<td><input type="time" name="slot1_tm"> </td>
</tr>
<tr>
<td colspan="2"><center>slot 2</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot2_dt"> </td>
<td><input type="time" name="slot2_tm"> </td>
</tr>
<tr>
<td colspan="2"><center><button type="submit" name="book" class="btn btn-default" value="book" style="font-size: 14px !important;">Book</button></center></td>
</tr>
</table>
<?php
if(isset($_REQUEST["book"]))
{
if($_REQUEST["book"])
{
$service_id=$_REQUEST["serv_id"];
$customer_id=$_REQUEST["cust_id"];
$slot1_dt=$_REQUEST["slot1_dt"];
$slot2_dt=$_REQUEST["slot2_dt"];
$slot1_tm=$_REQUEST["slot1_tm"];
$slot2_tm=$_REQUEST["slot2_tm"];
$slot1=$slot1_dt." ".$slot1_tm;
$slot1 = date("Y-m-d H:i:s",strtotime($slot1));
$slot2=$slot2_dt." ".$slot2_tm;
$slot2 = date("Y-m-d H:i:s",strtotime($slot2));
$insertqry="INSERT INTO `tblappointments`(`customer_id`, `service_id`, `preferred_slot1_date`, `preferred_slot2_date`) VALUES ('$customer_id','$service_id','$slot1','$slot2')";
mysqli_query($con, $insertqry) or die(mysqli_error($con));
}
}
?>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
it displays the result well but service_id is not passing to update it in the database
thanks in advance
use modal event listener,
$(document).ready(function(){
$('#edit-modal').on('show.bs.modal', function (e) {
var id = $(e.relatedTarget).attr('id');
alert(id);
$("#service_id").val(id);
});
});
and in modal in <form></form> add hidden input
<input type="hidden" id="service_id" name="serv_id" value="">
SideNote: Don't use $_REQUEST, instead use $_POST and escape the string.
$(document).on("click", "#upload_image", function () {
var myBookId = $(this).data('id');
$(".modal-body #activity_id___").val( myBookId );
console.log(myBookId);
// As pointed out in comments,
// it is superfluous to have to manually call the modal.
// $('#addBookDialog').modal('show');
});
<input type="hidden" name="activity_id___" id="activity_id___" value=""/>

Codeigniter Values not passing from view to controller in Form submit in bootstrap modal

I've a view in which a bootstrap modal is shown when a link is clicked. I've put a form submit in this modal. The fields inside bootstrap modal is filled through javascript. My problem is that when i submit the form, I'm not getting the values in POST in controller. I couldn't find where I've went wrong.
Here is my code:
View:
<script>
function showmodal(internaltt,indusid,eqptname,eqptmake,priority)
{
var complaintid=internaltt;
document.getElementById("nhiddenevent").value = complaintid;
document.getElementById("ninternaltt").value = complaintid;
document.getElementById("nindusid").value = indusid;
document.getElementById("faulty").value = eqptname;
document.getElementById("faultymake").value = eqptmake;
document.getElementById("priority").value = priority;
$('#responsiveshow').modal('show');
}
</script>
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
<th>
TT Number
</th>
<th>
Indus ID
</th>
<th>
Date
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<?php
if(isset($list) && !empty($list))
{
foreach($list as $complaints)
{
?>
<tr>
<td>
<?php echo $complaints->complaint_id;?>
</td>
<td>
<?php echo $complaints->indus_id;?>
</td>
<td>
<?php echo $complaints->created_date;?>
</td>
<td>
View
</td>
</tr>
<!------------ BEGIN MODAL ------------------------- -->
<!-- /.modal -->
<div id="responsiveshow" class="modal fade" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Complaints</h4>
</div>
<div>
<?php
echo form_open("index.php/complaints/registerindus"); ?>
<div class="modal-body">
<div class="scroller" style="height:300px" data-always-visible="1" data-rail-visible1="1">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label">TT Number</label>
<input type="text" placeholder="TT Number" class="form-control" name="ninternaltt" id="ninternaltt"/>
</div>
<div class="form-group">
<label class="control-label">Indus TT Number</label>
<input type="text" placeholder="Indus TT Number" class="form-control" name="nindustt" id="nindustt"/>
</div>
<div class="form-group">
<label class="control-label">Indus ID</label>
<input type="text" placeholder="Indus ID" class="form-control" name="nindusid" id="nindusid"/>
</div>
<div class="form-group">
<label class="control-label">Faulty Equipment</label>
<input type="text" placeholder="TT Number" class="form-control" name="faulty" id="faulty"/>
</div>
<div class="form-group">
<label class="control-label">Faulty Equipment Make</label>
<input type="text" placeholder="TT Number" class="form-control" name="faultymake" id="faultymake"/>
</div>
<div class="form-group">
<label class="control-label">Priority</label>
<input type="text" placeholder="TT Number" class="form-control" name="priority" id="priority"/>
<input type="hidden" name="nhiddenevent" id="nhiddenevent">
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn default">Close</button>
<input type="submit" class="btn green" value="Update Indus ID">
</div>
</div>
<?php echo form_close();?>
</div>
</div>
</div>
<!-- /.modal -->
<!-- --------------- END MODAL ------------ -->
<?php
}
}
?>
</tbody>
</table>
Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Complaints extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('complaints_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
public function registerindus()
{
$internaltt=$this->input->post('ninternaltt'); //here m not getting the values from view
$industt=$this->input->post('nindustt'); //here m not getting the values from view
$eturn=$this->complaints_model->updateIndusTT($internaltt,$industt);
if($return)
{
$this->index();
}
else
{
$this->listunregistered();
}
}
}
Can anyone help me to sort out this problem.. Thanks in advance
change
<?php echo form_open("index.php/complaints/registerindus"); ?>
to
<?php echo form_open("complaints/registerindus"); ?>
Here's a simple example: echo form_open('email/send');
The above example would create a form that points to your base URL plus the "email/send" URI segments, like this:
<form method="post" accept-charset="utf-8" action="http:/example.com/index.php/email/send" />
Also debug your code by echoing post values in controller function
then a typo here
$eturn=$this->complaints_model->updateIndusTT($internaltt,$industt);
should be
$return=$this->complaints_model->updateIndusTT($internaltt,$industt);

How can I select and edit mysql results based on which row is clicked?

Before I start, I'd just like to explain that I'm aware of the deprecation in MySQL and SQL Injections. This is purely for practice purposes.
I have a simple table with results from a mysql database using
mysql_fetch_assoc();
and then using a While loop to display the results in a table.
I'm using Twitter-Bootstrap as a CSS Framework and to also handle the Modals explained further on.
Here is the output
Now what I wish to do is to trigger a Modal using the edit button which will contain that specific row's data in a form. Getting the modal to trigger is not a problem, it's displaying the specific row's data within the modal dependent on which row has had the edit button clicked. As for the Form, there will be 4 <input>'s with a submit button at the bottom of the Modal to update the results in the database. I will most likely be handling that with a $.POST/Ajax method rather than php as it'd be nice to refresh the table without having to reload the page after the modal has closed.
I'm confident in being able to update the results but it's just getting "$(this)" 's data to be displayed dependant on which result wants to be edited.
Here is an image of the modal when triggered by clicking on the edit button.
How could I do this?
Here's my code.
<table class="table users table-bordered table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($result)) { $id=$row['id']; $name=$row['name']; $desc=$row['description']; $quantity=$row['quantity']; $price=$row['price']; echo "<tr id='data-form' >
<td>$id</td>
<td>$name</td>
<td>$desc</td>
<td>$quantity</td>
<td>". '$'. "$price</td>
<td><button href='#Edit' data-toggle='modal' class='btn btn-success'>Edit</button>
</td>
<td><button class='btn btn-danger'>Delete</button>
</td>
</tr>"; } ?>
</tbody>
</table>
<div id="Edit" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button">×</button>
<h3>Edit Item</h3>
</div>
<div id="inner-data" class="modal-body">
<label>Name:</label>
<input type="text" class="form-control" value="test" id="name">
<br>
<label>Description:</label>
<input type="text" class="form-control" value="test" id="description">
<br>
<label>Quantity:</label>
<input type="text" class="form-control" value="test" id="quantity">
<br>
<label>Price:</label>
<input type="text" class="form-control" value="test" id="price">
<br>
</div>
<div class="modal-footer"> <a data-dismiss="modal" id="updateResults" class="btn btn-primary btn-small" href="#">Save</a>
</div>
</div>
</div>
</div>

Create a Search records form through Bootstrap Modals PHP MySQL

I'm building a form within a Boostrap Modal, it has 3 INPUT fields and a Submit button for each row. Each Submit is POST onto another page. What I then want to do is use the variables to return data into a table which will show all the results for that particular search ie Postcode, StreetName. Within the table I have a SUBMIT button which will return the output into my main form on the main page.
The section I'm struggling with is to get the variable from the INPUT (from my modal, which I'm using on jobdetailssearch.php) to POST onto the search page (search.php). Once this is return then I'm going to show all the results in the form on my jobdetails page (jobdetails.php)
This below is my code for the 3 pages.
jobdetailssearch.php
<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="includes/search.php" 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 width="100px"><i class="fa fa-list-alt"></i> Address</th>
<th width="50px"></th>
</tr>
</thead>
<tbody>
<tr>
<td width="100px"></td>
<td width="50px">Select Address</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer right">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
<!--<button type="submit" class="btn blue">Select</button>-->
</div>
</form>
</div>
search.php
<?php
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);
$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>'.$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" name="viewsearch">View Address</button>
</form>
</td>';
}
}
?>
The modal opens fine and shows the form in the way I want. What's the best way I should go about this to input the search criteria and show the results in a table for me to select and pull on to my main form on jobdetails.php (I've not included this as it's too big and not sure its needed to be seen)?
Let me know if I understood your issue, you have your form in a modal view of bootstrap and you want send the data in the form to another page, process the search and then return the data that you find to the same modal and put it into the < tables> that's your issue?
Well, if that is. Look I think the easier way to do this is using jquery, and change the input submit for a input button, because I don't remember very well but when you send a submit inside the modal, the modal it's closed. That's true? if that the problem change the submit for a button. Then you have to create a function .click() to the button to catch the event click, with the .serialize() (if you want to check that you really are recieving the data you can make a die(var_dump($_POST)); in the php and check it in the console with firebug or something like that.) you get the data of your < form> and then you have to send it with a .post() to the other file, in the php you recive the data and When you recive the response you can put it into the table with .html().
So the code that I'm thinking should look like this, uou can change it to make it how you need it, but this can be the base:
JQUERY CODE:
$(document).ready(function(){
$("#yourButtonID").click(function(){
data = $("#yourFormID").serialize();
$.post("yourPHPfileToSearch.php",data,function(dataReturn)){
$("#yourTableID").html(dataReturn);
});
});
});
Let me know if you need more helpe. Regards. Have a nice day.

Categories