I want to filter the table by using multiple select checkbox by selecting multiple Company Name and the table will display the record related to the selected checkbox. It only able to select one checkbox and display one related record only but it cannot multiple select checkbox.
<form name="frmSearch" id="frmSearch" method="post" action="">
<label>Company Name </label>
<select id="multiple-checkboxes" multiple="multiple" name="COMPANYNAME">
<?php
$query = mysqli_query($conn_connection, "SELECT * FROM sl_iv GROUP by COMPANYNAME");
while ($row = mysqli_fetch_assoc($query)) {
echo "<option value='".$row["COMPANYNAME"]."'".($row["COMPANYNAME"]==$_POST["COMPANYNAME"] ? " selected" : "").">".$row["COMPANYNAME"]."</option>";
}
?>
</select>
<br></br>
<button type="submit" id="submit" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button>
<a href="cust_due_list.php">
<button type="button" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-refresh"></span> RESET</button>
</a>
<br></br>
<table id="table">
<center>
<thead>
<tr class="item-row">
<th width="15%" style="text-align:center"><span>Doc No.</span></th>
<th width="10%" style="text-align:center"><span>Due</span></th>
<th width="5%" style="text-align:center"><span>Age</span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Ammount</span></th>
<th width="10%" style="text-align:center"><span>Payment</span></th>
<th width="10%" style="text-align:center"><span>OutStanding</span></th>
</tr>
</thead>
</center>
<tbody>
<?php
if(isset ($_POST['COMPANYNAME']))
{
$COMPANYNAME = $_POST['COMPANYNAME'];
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME = '".$COMPANYNAME."' or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$docamt = $row['DOCAMT'];
?>
<tr class="item-row">
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DocNo" id=DocNo0 " name="DocNo " value="<?php echo htmlspecialchars($row[ 'DOCNO']);?>" readonly></td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DueDate" id="DueDate0" name="DueDate" value="<?php echo htmlspecialchars($row['DUEDATE']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm DateAge" id="DateAge0" name="DateAge" value="<?php echo $dateage;?>" readonly>
</td>
<td>
<input type="text" style="text-align:center; font-size:15px" class="form-control input-sm CompanyName" id="CompanyName0" name="CompanyName" value="<?php echo htmlspecialchars($row['COMPANYNAME']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly>
</td>
<td>
<input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly>
</td>
</tr>
<?php
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#multiple-checkboxes').multiselect();
});
</script>
When you receive multiple-select POST it cames as array, so you should use "IN" operator in your mysql request instead of comparison.
Try to change one part of your code:
if(isset ($_POST['COMPANYNAME'])) {
$COMPANYNAME = $_POST['COMPANYNAME'];
$COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
$companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
$fetch = "SELECT sl_iv.DOCDATE, ar_iv.DUEDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME, ar_iv.DOCAMT, ar_iv.PAYMENTAMT FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME IN (".$companiesParam.") or sl_iv.DOCDATE <= '".$from."'";
$result = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
}
Related
basically I work on foreach loop to fetch users, i assume having 6 from database and then each of those 6 users have 3 input each, which values from 3 of those input have to sum with each other. I want to have total_sum differently between those 6 users. How do i achieve that?
Here are my code
<tbody>
<form action="payment-code.php" method="POST">
<?php
$query = "SELECT * FROM staffs";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run) > 0){
foreach($query_run as $rows)
{
?>
<tr>
<td>
<?=$rows['staff_id']; ?>
</td>
<td>
<?=$rows['firstname'] . $rows['surname']; ?>
</td>
<td>
<input type="text" name="salary" class="form-control" placeholder="salary">
</td>
<td>
<input type="text" name="totalbonus" class="form-control" placeholder="total bonus">
</td>
<td>
<input type="text" name="totalfee" class="form-control" placeholder="total fee">
</td>
<?php
}
else{
?>
<td colspan="5">No record found!</td>
<?php
}
}
?>
</tr>
</form>
</tbody>
I want to sum 3 of (salary + total bonus + total fee ) and get total amount inside foreach. How can i achieve that?
Hope this will help
<form action="payment-code.php" method="POST">
<table>
<?php
$query = "SELECT * FROM staffs";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run) > 0) {
foreach($query_run as $rows) {
echo `
<tr>
<td>
` . $rows['staff_id'] . `
</td>
<td>
` . $rows['firstname'] . $rows['surname'] . `
</td>
<td>
<input type="text" name="salary" class="form-control" placeholder="salary">
</td>
<td>
<input type="text" name="totalbonus" class="form-control" placeholder="total bonus">
</td>
<td>
<input type="text" name="totalfee" class="form-control" placeholder="total fee">
</td>`;
}
}
else {echo `<td colspan="5">No record found!</td>`;}
?>
</table>
Or without echo
<tbody>
<form action="payment-code.php" method="POST">
<?php
$query = "SELECT * FROM staffs";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run) > 0){
foreach($query_run as $rows)
{
?>
<tr>
<td>
<?= $rows['staff_id']; ?>
</td>
<td>
<?=$rows['firstname'] . $rows['surname']; ?>
</td>
<td>
<input type="text" name="salary" class="form-control" placeholder="salary">
</td>
<td>
<input type="text" name="totalbonus" class="form-control" placeholder="total bonus">
</td>
<td>
<input type="text" name="totalfee" class="form-control" placeholder="total fee">
</td>
<?php
}
}
else {
?>
<td colspan="5">No record found!</td>
<?php
}
?>
</tr>
</form>
</tbody>
UPDATE:
I have managed to correct some things. But only the first row is inserted. If the first row is not selected, nothing gets inserted.
I want only selected checkboxes from the populated table inserted into the a new table.
My table is as follows:
<table id="simple-table" class="table table-striped table-condensed responsive">
<thead>
<tr>
<th style="width:5%" class="center">
<label class="pos-rel">
<input type="checkbox" name="checked" class="ace" />
<span class="lbl"></span>
</label>
</th>
<th style="width:32%">Student Name</th>
<th style="width:13%">Adm. No</th>
<th style="width:10%" class="center">CA1 (10%)</th>
<th style="width:10%" class="center">CA2 (10%)</th>
<th style="width:10%" class="center">CA3 (10%)</th>
<th style="width:10%" class="center">Exam (70%)</th>
<th style="width:10%" class="center">Total (100%)</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['loadStudents'])){
$session = clean($_POST["session"]);
$term = clean($_POST["term"]);
$c_taught = clean($_POST["c_taught"]);
$s_taught = clean($_POST["s_taught"]);
$process_limit = clean($_POST["process_limit"]);
$session_phrase = "Session";
$sql = "SELECT `id`, `StudentID`, `StudentName` FROM tbl_students WHERE `StudentClass` = '".$c_taught."' ORDER BY `StudentName` ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$cnt=1;
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$student_name = $row['StudentName'];
$student_id = $row['StudentID'];
?>
<tr>
<td class="center">
<label class="pos-rel">
<input type="checkbox" class="ace" name="checked[]" value="<?php echo $row['id'];?>" />
<span class="lbl"></span>
</label>
</td>
<td><?php echo $student_name; ?><input type="hidden" name="student_name[]" value="<?php echo $row['StudentName']; ?>"/></td>
<td><?php echo $student_id; ?><input type="hidden" name="student_id[]" value="<?php echo $row['StudentID']; ?>"/></td>
<td class="center"><?php echo '<input type="text" maxlength="2" size="6" name="CA1[]" autofocus>'; ?></td>
<td class="center"><?php echo '<input type="text" maxlength="2" size="6" name="CA2[]">'; ?></td>
<td class="center"><?php echo '<input type="text" maxlength="2" size="6" name="CA3[]">'; ?></td>
<td class="center"><?php echo '<input type="text" maxlength="2" size="6" name="Exam[]">'; ?></td>
<td class="center"><?php echo '<input type="text" maxlength="2" size="6" name="Total[]">'; ?></td>
</tr>
<?php $cnt=$cnt+1;}}
else {
$msg = "<span class='red'><h4> No data available for your selection. </h4></span>";
}
}
?>
</tbody>
</table>
My inset script is as follows: (On the same page with the form)
<?php
$enroll_sql = "";
if(isset($_POST['add_assessment'])) {
if(empty($_POST['checked'])){
echo '<script>alertify.alert("No Student is selected.",function(e){if(e){document.location.href = "cass_entry.php";}}).set("labels", {ok:"OK!"}).set("defaultFocus", "ok").set("title", "Assessment")
</script>';
exit();
}
foreach($_POST['checked'] as $id=>$value) {
$session = $_POST['session'];
$term = $_POST['term'];
$c_taught = $_POST['c_taught'];
$s_taught = $_POST['s_taught'];
$student_id = $_POST['student_id'][$id];
$student_name = $_POST['student_name'][$id];
$ca_1 = $_POST['CA1'][$id];
$ca_2 = $_POST['CA2'][$id];
$ca_3 = $_POST['CA3'][$id];
$exam = $_POST['Exam'][$id];
$total = $_POST['Total'][$id];
$enroll_sql .= '
INSERT INTO tbl_subjects_enrollment (`Session`,`Term`,`Student_Class`,`Subject_Name`,`Student_ID`,`Student_Name`,`CA_1`,`CA_2`,`CA_3`,`Exam`,`Total`)
VALUES("'.$session.'", "'.$term.'", "'.$c_taught.'", "'.$s_taught.'", "'.$student_id.'", "'.$student_name.'", "'.$ca_1.'", "'.$ca_2.'", "'.$ca_3.'", "'.$exam.'", "'.$total.'")';
echo $enroll_sql;
if (mysqli_multi_query($conn, $enroll_sql)) {
$success_msg = '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="ace-icon fa fa-times"></i>
</button>
<h4><i class="ace-icon fa fa-check"> Success</i></h4>
<p>Assessment scores were successfully saved.</p></div>';
} else {
echo "Error saving Assessment: " . $conn->error;
}
}
}
?>
Watch, your first checkbox isn't named as an array and has no value :
<input type="checkbox" name="checked" class="ace" />
It may result in a simple var $_POST['checked'] which isn't an array (nor a string since it hasn't value) and won't be passed in your foreach.
Look :
foreach($_POST['checked'] as $id=>$value) {
$enroll_sql .= '
INSERT INTO tbl_subjects_enrollment (`Session`,`Term`,`Student_Class`,`Subject_Name`,`Student_ID`,`Student_Name`,`CA_1`,`CA_2`,`CA_3`,`Exam`,`Total`)
VALUES("'.$session.'", "'.$term.'", "'.$c_taught.'", "'.$s_taught.'", "'.$student_id.'", "'.$student_name.'", "'.$ca_1.'", "'.$ca_2.'", "'.$ca_3.'", "'.$exam.'", "'.$total.'")';
echo $enroll_sql;
if (mysqli_multi_query($conn, $enroll_sql)) {
$success_msg = '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="ace-icon fa fa-times"></i>
</button>
<h4><i class="ace-icon fa fa-check"> Success</i></h4>
<p>Assessment scores were successfully saved.</p></div>';
} else {
echo "Error saving Assessment: " . $conn->error;
}
}
You concatenate your SQL query each time => and execute it each time adding the previous queries.
If you didn't forget your semi-colon it would have ended inserting too many time the same line (and actually that's why only the first Insert is working).
The problem here is the concatenation of the query AND the missing semi-colon of your query.
In order to make your code work fine, you juste have to not concatenate your query :
$enroll_sql = '...'; // = not .=
OR
let it concatenated BUT execute the query OUTSIDE your foreach loop (and adding a semi-colon at the end of the SQL query :
, "'.$total.'");'; // ; at the end of the query
I wanna thank all contributors especially #WizardNx.
I eventually solved it (Necessity is the mother of creativity):
It appears the checkbox was not assigning unique id to each row. In fact, if I check row_3 and fill all the inputs, it will insert for row_1 but assign row_3 id.
Here is what I did:
<tr>
<td class="center">
<label class="pos-rel">
<input type="checkbox" class="ace" name="studentSelect[<?php echo $row['id']; ?>]" value="<?php echo $row['StudentID']; ?>" />
<span class="lbl"></span>
</label>
</td>
<td><?php echo $row['StudentName']; ?><input type="hidden" name="student_name[<?php echo $row['id']; ?>]" value="<?php echo $row['StudentName']; ?>"/></td>
<td><?php echo $row['StudentID']; ?></td>
<td class="center"><input type="text" maxlength="2" size="6" name="CA1[<?php echo $row['id']; ?>]" autofocus></td>
<td class="center"><input type="text" maxlength="2" size="6" name="CA2[<?php echo $row['id']; ?>]"></td>
<td class="center"><input type="text" maxlength="2" size="6" name="CA3[<?php echo $row['id']; ?>]"></td>
<td class="center"><input type="text" maxlength="2" size="6" name="Exam[<?php echo $row['id']; ?>]"></td>
<td class="center"><input type="text" maxlength="2" size="6" name="Total[<?php echo $row['id']; ?>]"></td>
</tr>
I added id to each input on each row.
<div class="col-xs-12 col-md-10" style="padding:0px 100px 0px 50px; color:blue;">
<form action="#" style="color:blue;" method="POST" >
<div class="well well-sm" >
<table border="collapse; border-spacing:5px;" style="background-color:pink;">
<thead>
<th>Stock ID</th>
<th>Medicine Name</th>
<th>Quantity Unit</th>
<th>Unit Price</th>
<th>Selling Price</th>
<th>Sold Quantity</th>
<th>Total Price</th>
<th><input type="button" value="+" id="add" class="btn btn-primary"></th>
</thead>
<tbody class="detail">
<tr>
<td><input type="text" class="form-control" id="si" name="si"></td>
<td><input type="text" class="form-control" id="mn" name="mn" value="<?php
include_once('classes/class.select.php');
$bill = new select();
$value = $bill ->billing($_POST['si']);
foreach($value as $row){
echo $row["medi_name"];
}
?>"></td>
<td><input type="text" class="form-control" id="qu" name="qu" value="<?php echo $row["quantity_unit"];?>"></td>
<td>
<input type="text" class="form-control" id="up" name="up" value="<?php echo $row["unit_price"]; ?>"></td>
<td>
<input type="text" class="form-control" id="sp" name="sp" value="<?php echo $row["selling_price"];?>"></td>
<td><input type="text" class="form-control" id="t" name="t" ></td>
<td><input type="text" class="form-control" id="ls" name="ls" ></td>
<td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
This is my table of billing system of medicine. When we give stock Id, the other columns are automatically fill according to relevant stock Id. I want to add some more rows to this table like this. But when I click on bill button on second row, whole row will be disappeared. I also want to calculate whole total price of the end.
<script>
function addnew(){
var n=($('.detail tr').length-0)+1;
var tr =
'<tr>' +
'<td><input type="text" class="form-control" id="si" name="si"></td>'+
'<td><input type="text" class="form-control" id="mn" name="mn" value="<?php
include_once('classes/class.select.php');
$bill = new select();
$value = $bill ->billing($_POST['si']);
foreach($value as $row){
echo $row["medi_name"];
}
?>"></td>'+
'<td><input type="text" class="form-control" id="qu" name="qu" value=["quantity_unit"]></td>'+
'<td><input type="text" class="form-control" id="up" name="up" value=["unit_price"]></td>'+
'<td><input type="text" class="form-control" id="sp" name="sp" value=["selling_price"]></td>'+
'<td><input type="text" class="form-control" id="t" name="t" ></td>'+
'<td><input type="text" class="form-control" id="ls" name="ls" ></td>'+
'<td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>'+
'</tr>';
$('.detail').append(tr);
}
$(function(){
$('#add').click(function(){
addnew();
});
});
</script>
$("#cloneTable tfoot #addNew").on("click", function() {
var clonedRow = $('#cloneTable tbody tr:first').clone();
clonedRow.find('input').val('');
$('#cloneTable tbody').append(clonedRow) ;
});
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I have problem in this code. When I press "show button" I want data from database shows in text box and "modify" and "delete" buttons work.
But in this code when I press show button it shows error Notice: Undefined index: first_name, I am stuck in this code. How to resolve this?
include '../../../../database/dbConnection.php';
//-------------------------------------------
$row[0]="";
$isSaveDisabled = true;
$isCreateDisabled=false;
$isModifyDiasbled=true;
$isDeleteDisabled=true;
if (isset ($_POST['create_button'])) {
$isSaveDisabled = false;
$isCreateDisabled=true;
$sql="select ifnull(max(user_id),10000)+1 from user_master";
$res= mysql_query($sql);
$row= mysql_fetch_array($res);
$row[0];
}
if(isset($_POST['modify_button']))
{
}
if(isset($_POST['delete_button']))
{
}
?>
<!--
PHP CODE ENDS FROM HERE-------------------------
-->
<!--
BOOTSTRAP START FROM HERE-------------------------
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../bootStrap/css/bootstrap.css">
<link rel="stylesheet" href="../../../../bootStrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../../../../css/StyleSheet.css">
<script src="../../../../js/ValidateKeyPress.js"></script>
<title></title>
<script>
</script>
</head>
<body>
<p id="demo"></p>
<!-- <div class="page-header1">
Hello
</div>-->
<div class="container jumbotron ">
<div class=" text-center"><h4>USER CREATION</h4></div>
<form class="form-inline " action="" method="POST" name="myForm">
<div class="form-group1">
<label class="control-label" for="ec" id="myID">ENTITY CODE</label>
<select class="form-control2" name="ecode" id="myID">
<option value="">SELECT ENTITY CODE</option>
<option>DOC</option>
<option>EMP</option>
<option>NUR</option>
<option>ORG</option>
<option>TEC</option>
<option>VEN</option>
</select>
</div>
<div class="form-group1">
<label class="control-label" for="uid">USER ID</label>
<input type="text" class="form-control2" name="userid" value="<?php echo $row[0];?>">
</div>
<hr>
<table class="table1 table-borderless table-responsive">
<tbody>
<?php
if(isset($_POST['select_button']))
{
$qrydatabind='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER ORDER BY user_id DESC
LIMIT 1';
$results1= mysql_query($qrydatabind) or die(mysql_error());
while( $row = mysql_fetch_array( $results1 ) ) {
}
}
?>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="finame" id="myID1" >FIRST NAME</label></td>
<td><input value="<?php echo $row["first_name"]; ?>" type="text" class=" form-control2 input-sm text-uppercase"name="firstname" onkeypress="return allCharacter(event);" ></td>
<td><label class="control-label" for="mname">MIDDLE NAME</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="middlename"></td>
<td><label class="control-label" for="lname" id="myID2">LAST NAME</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="lastname" onkeypress="return allCharacter(event);"></td>
</tr>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="fname">FATHER NAME</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="fathername"></td>
<td><label class="control-label" for="moname">MOTHER NAME</label></td>
<td><input type="text" class="form-control2 input-sm text-uppercase" name="mothername"></td>
<td><label class="control-label" for="nod">NO.OF DEPENDENTS</label></td>
<td><input type="text" class="form-control2 input-sm text-uppercase" name="nod"></td>
</tr>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="dob" id="myID3">D.O.B</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="dob" placeholder="DD/MM/YYYY" id="myID3" ></td>
<td><label class="control-label" for="gen" id="myID4">GENDER</label></td>
<td><select id="myID4" class="form-control2" name="gender">
<option value="">SELECT GENDER</option>
<option>M</option>
<option>F</option>
<option>o</option>
</select></td>
<td><label class="control-label" for="idm">IDENTIFICATION MARK</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="idmark"></td>
</tr>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="ms">MARITAL STATUS</label></td>
<td><select class=" form-control2" name="mstatus">
<option value="">SELECT STATUS</option>
<option>M</option>
<option>U</option>
</select></td>
<td><label class="control-label" for="sname">SPOUSE NAME</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="spname"></td>
<td><label class="control-label" for="mno" id="myID5">MOBILE NO.</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="mobileno" maxlength="12" onkeypress="return allnumeric(event);"></td>
</tr>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="em">EMAIL-ID</label></td>
<td><input id="myID6" type="text" class="form-control2 input-sm text-uppercase" name="email" placeholder="sample#gmail.com"></td>
<td><label class="control-label" for="adhar">ADHAR-ID</label></td>
<td><input type="text" class="form-control2 input-sm text-uppercase" name="adharid"></td>
<td><label class="control-label" for="paname">PAN NUMBER</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="pannumber"></td>
</tr>
<tr>
<th scope="row"></th>
<td><label class="control-label" for="passno">PASSPORT NO.</label></td>
<td><input type="text" class="form-control2 input-sm text-uppercase" name="passportno"></td>
<td><label class="control-label" for="tno">TIN NUMBER</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="tinnumber"></td>
<td><label class="control-label" for="dno">DL NUMBER</label></td>
<td><input type="text" class=" form-control2 input-sm text-uppercase" name="dlnumber"></td>
</tr>
</tbody>
</table>
<div class="btn-group-sm2 text-center">
<button type="submit" class="btn btn-primary" name="create_button" <?php echo $isCreateDisabled?'disabled':'';?>>CREATE</button>
<?php
if($isCreateDisabled) {
echo '<script>document.getElementById("myID").style.color = "red";</script>';
echo '<script>document.getElementById("myID1").style.color = "#ff0000";</script>';
echo '<script>document.getElementById("myID2").style.color = "#ff0000";</script>';
echo '<script>document.getElementById("myID3").style.color = "#ff0000";</script>';
echo '<script>document.getElementById("myID4").style.color = "#ff0000";</script>';
echo '<script>document.getElementById("myID5").style.color = "#ff0000";</script>';
echo '<script>document.getElementById("myID6").style.color = "#ff0000";</script>';
}
?>
<button type="submit" class="btn btn-primary" name="modify_button"<?php echo $isModifyDiasbled?'disabled':'';?>>MODIFY</button>
<button type="submit" class="btn btn-primary" name="delete_button" <?php echo $isDeleteDisabled?'disabled':'';?>>DELETE</button>
<button type="submit" class="btn btn-primary" name="clear_button">CLEAR</button>
<button type="submit" class="btn btn-primary " name="save_button" <?php echo $isSaveDisabled?'disabled':''; ?> onclick="return validateForm();">SAVE</button>
<button type="submit" class="btn btn-primary" name="exit_button">EXIT</button>
<button type="submit" class="btn btn-default text-right" name="search_button">SEARCH</button>
<button type="submit" class="btn btn-default text-right" name="select_button">SHOW</button>
</div>
</form>
</div>
</tbody>
<div class="table-responsive">
<table class="table">
<?php
if(isset($_POST['save_button'])){
$isCreateDisabled=false;
if(isset($_POST['ecode']) && isset($_POST['firstname'])&& isset($_POST['middlename'])&& isset($_POST['lastname'])
&& isset($_POST['fathername'])&& isset($_POST['mothername'])&& isset($_POST['nod']) && isset($_POST['dob'])
&& isset($_POST['gender'])&& isset($_POST['idmark'])&& isset($_POST['mstatus'])&& isset($_POST['spname'])
&& isset($_POST['mobileno'])&& isset($_POST['email'])&& isset($_POST['adharid'])&& isset($_POST['pannumber'])
&& isset($_POST['passportno'])&& isset($_POST['tinnumber'])&& isset($_POST['dlnumber']))
{
$ecode=$_POST['ecode']; $first_name=$_POST['firstname']; $middle_name=$_POST['middlename'];
$last_name=$_POST['lastname']; $father_name=$_POST['fathername']; $mother_name=$_POST['mothername'];
$number_of_dependents=$_POST['nod']; $dob=$_POST['dob']; $gender=$_POST['gender'];
$identification_mark=$_POST['idmark']; $marital_status=$_POST['mstatus'];
$spouse_name=$_POST['spname']; $mobile_number=$_POST['mobileno']; $email_id=$_POST['email'];
$adhar_id=$_POST['adharid'];$pan_number=$_POST['pannumber']; $passport_number=$_POST['passportno'];
$tin_number=$_POST['tinnumber']; $dl_number=$_POST['dlnumber'];
}
$qry="insert into user_master(ecode, first_name, middle_name, last_name, father_name, mother_name,
number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
email_id, adhar_id, pan_number, passport_number, tin_number, dl_number)
VALUES('$ecode','$first_name','$middle_name','$last_name','$father_name','$mother_name',
'$number_of_dependents',str_to_date('$dob','%d/%m/%Y'),'$gender','$identification_mark','$marital_status',
'$spouse_name','$mobile_number','$email_id','$adhar_id','$pan_number',
'$passport_number','$tin_number','$dl_number')";
$resultss= mysql_query($qry) or die(mysql_error());
if($resultss)
{
echo "<script>
alert('SuccessFully');
</script>";
}
else
{
return "Error...! Not Inserted.";
}
$qrydatabind='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER ORDER BY user_id DESC
LIMIT 1';
$results= mysql_query($qrydatabind) or die(mysql_error());
while( $row = mysql_fetch_array( $results ) ) {
echo
"
<div class='table-responsive'>
<table border='1' style= 'background-color: #84ed86; color: #761a9b; ' >
<thead>
<tr>
<th></th>
<th>Entity Code</th>
<th>User Id</th> <th>User Name</th> <th>Father Name</th> <th>Mother Name</th> <th>No.Of Dependents</th>
<th>D.O.B</th> <th>GENDER</th> <th>Id Mark</th> <th>MARITAL STATUS</th> <th>SPOUSE NAME</th>
<th>Mob. Number</th> <th>E-Id</th> <th>ADHAR-ID</th> <th>PAN-No.</th> <th>PASSPORT-No.</th>
<th>TIN-NO.</th> <th>DL-No.</th>
</tr>
</thead>
<tr >
<td> </td>
<td>{$row['ecode']}</td> <td> echo $row[0];</td>
<td>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</td>
<td>{$row['father_name']}</td> <td>{$row['mother_name']}</td>
<td>{$row['number_of_dependents']}</td> <td>{$row['dob']}</td>
<td>{$row['gender']}</td> <td>{$row['identification_mark']}</td>
<td>{$row['marital_status']}</td> <td>{$row['spouse_name']}</td>
<td>{$row['mobile_number']}</td> <td>{$row['email_id']}</td>
<td>{$row['adhar_id']}</td> <td>{$row['pan_number']}</td>
<td>{$row['passport_number']}</td> <td>{$row['tin_number']}</td>
<td>{$row['dl_number']}</td>
</tr> </table>
</div>";
}}
?>
</table>
</div>
</body>
</html>
If edits and delete work that means your select statement is wrong. Maybe u are not properly declaring your fields in your select statement. Id look into that first. What I do when my sql is on error is open up an sql session and try doing the query straight from the sql editor.
Also,
why are you using limit 1? You are fetching a result of records for an array but you are limiting your query to one row?
EDIT:
Dont you have to select user_id in order to use ORDER BY? All you have to do is add user_id to select statement
I am trying to send my dynamic table to mysql database but I am having difficulties. I've tried using a for to get it to send but I'm not getting very far. At the moment I am just displaying it but I really want to send it to mysql. I want all the data to be in one row with the rest of the data like test case name, test case number and so on. But the dynamic table must be put into the same row where the rest of the data goes.
Below you will see what I have done and maybe you can see what my intentions are...
<div class="col-md-6">
<label>Test Case Number:</label>
<?php
$sql = "SELECT test_case_number FROM qa_testing_application ORDER BY id desc LIMIT 1";
$result = mysqli_query($database, $sql) or trigger_error("SQL", E_USER_ERROR);
while ($row = mysqli_fetch_assoc($result)) {
?>
<input class="form-control" style="display: none" type="text" name="test_case_number" readonly="readonly" value="<?php echo $row['test_case_number']+3?>">
<?php } ?>
<label>Company Name:</label>
<input class="form-control" type="text" name="test_case_company_name"/>
<label>Tester:</label>
<input class="form-control" style="display: none" type="text" name="user_username" value="<?php echo $user_username ?>" readonly/>
<label>System:</label>
<input class="form-control" type="text" name="test_case_system"/>
<label>URL:</label>
<input class="form-control" type="text" name="test_case_url"/>
</div>
<div class="col-md-12" style="border: 1px solid #28415b; padding-bottom: 12px; padding-top: 12px;margin-top: 20px; margin-bottom: 15px">
<p>
<INPUT class="btn btn-primary ladda-button" type="button" value="Add row" onclick="addRow('dataTable')" />
<INPUT class="btn btn-primary ladda-button" type="button" value="Delete row" onclick="deleteRow('dataTable')" />
</p>
<div class="clear"></div>
<p>'All fields below are compatible to use markdowns for editing' </p>
<table class="table table-hover">
<thead>
<tr>
<th style="width: 15px">Chk</th>
<th style="width: 335px">Action:</th>
<th style="width: 326px;">Expected System Response:</th>
<th style="width: 151px;">Pass/ Fail</th>
<th>Comment</th>
</tr>
</thead>
</table>
<table id="dataTable" class="table table-hover">
<tbody>
<tr>
<td style="width:20px;"><INPUT type="checkbox" name="chk[]" id="chk"/></td>
<td><INPUT class="form-control" type="text" name="step[]" autocomplete="on" placeholder="Action" required/></td>
<td><INPUT class="form-control" type="text" name="url[]" autocomplete="on" placeholder="Expected Outcome" required/></td>
<td>
<select name="passfail[]" class="form-control" style="width:120px;">
<OPTION value="Pass">....</OPTION>
<OPTION value="Pass">Pass</OPTION>
<OPTION value="Fail">Fail</OPTION>
</select>
</td>
<td>
<TEXTAREA class="form-control" type="text" name="comment[]" rows="2" cols="15" placeholder="Comment" required></TEXTAREA>
</td>
</tr>
</tbody>
</table>
Thats my table that i am dynamically making...
In my PHP file i display the dynamic table as follows:
<table class="table table-bordered">
<thead>
<tr>
<td>Step</td>
<td>process</td>
<td>Expected System Response</td>
<td>
<center>Pass/ Fail</center>
</td>
<td>Comment</td>
</tr>
</thead>
<?php
if (isset($_POST)) {
$step = $_REQUEST['step'];
$url = $_REQUEST['url'];
$pass_fail = $_REQUEST['passfail'];
$comment = $_REQUEST['comment'];
$countPass = 0;
$countFail = 0;
foreach ($step as $key => $row) {
?>
<tbody>
<tr>
<td><?php echo $key + 1; ?></td>
<td><?php echo $step[$key]; ?></td>
<td><?php echo $url[$key]; ?></td>
<td style="color:<?php if ($pass_fail[$key] == 'Fail') {
echo 'color: red';
} else {
echo 'limegreen';
} ?>"><b>
<center><?php echo $pass_fail[$key]; ?></center>
</b></td>
<td><?php echo $comment[$key]; ?>
</td>
</tr>
</tbody>
</table>
Now how do i insert it into mysql???
So basically what you need to do to insert it into your database is doing a sql query in PHP.
Let me show you an code example:
//establish db connection
$con=mysqli_connect("dbhost","username","dbpassword","dbname");
$sql = "INSERT INTO tablename (name_of_row1,
name_of_row2,
name_of_row3)
VALUES ('".$value1."',
'".$value2."',
'".$value3."')";
mysqli_query($con, $sql);
mysqli_close($con);
So you have to open a sql connection and then insert your data to the table you want. I hope this it's clear enough. Now if the PHP file gets called the SQL query is beeing made.